Optionally provide private feedback to help us improve this article...

Thank you for your feedback!


Limit InstantForum Access to Only Logged In Users

If you wish to ensure that users logon or register within your InstantForum community before they can access any page within your community you can achieve this by adding a small snippet of code into the MasterPage.Master file for your skin.

You can also use <authorization> tags via the web.config however using a code based approach gives us more control and allows for example to redirect users back to your web site or any URL of your choice.

Adding the Redirect Code

To add the redirect code please follow the steps below...

1. Navigate to your Skins/{YourSkinName}/.

2. Open the MasterPage.Master file within NotePad or similar text editor.

You'll see within the MasterPage.Master an existing code block as shown below...

<script runat="server" language="c#">

public void Page_Load(Object sender, EventArgs e) {

// you can include optional server side code here that will execute on every page
base.Page_Load(sender,e);

}

</script>

Replace this entire code block the following new code to perform the redirect to all anonymous users....

<script runat="server" language="c#">

public void Page_Load(Object sender, EventArgs e) {

if (InstantASP.InstantForum.HttpContext.ForumContext.Current.CurrentUser.UserID == 0)
{
if (!IsAllowed()) {
Response.Redirect("Logon.aspx");
}
}

// you can include optional server side code here that will execute on every page
base.Page_Load(sender,e);

}

private bool IsAllowed() {

if (Request.RawUrl.ToString().ToLower().IndexOf("logon.aspx") >= 0 ||
Request.RawUrl.ToString().ToLower().IndexOf("register.aspx") >= 0 ||
Request.RawUrl.ToString().ToLower().IndexOf("sendvalidationcode.aspx") >= 0 ||
Request.RawUrl.ToString().ToLower().IndexOf("activate.aspx") >= 0 ||
Request.RawUrl.ToString().ToLower().IndexOf("resetpassword.aspx") >= 0)
{
return true;
}
return false;

}

</script>

3. Save your updated MasterPage.Master file. You do not need to recompile anything.

The IsAllowed() method allows you to white list specific files if you do wish to allow access to certain pages.

Testing the Results

Now attempt to navigate to your InstantForum installation. If your not already logged in you should be automatically redirected to the InstantForum login page. The only other areas you are allowed to access allow you to register, activate your account or reset your password.