Articles

Kentico and Password Protected Templates

January 08, 2007 (Kentico)


When using the Kentico system one often creates templates for password protected cotnent. If you look at these templates in the Kentico admin they will redirect to the log in page because a system user is not logged in. This code snippet prevents the redirection inside the Kentico manager.

In the script section at the top of the template add the following as a new Page_Load subroutine or too the beginning of the current routine.


// if not logged in, return to log in page
private void Page_Load(object sender, System.EventArgs e)
{
if (Convert.ToInt32(Session["CMSUserID"])==0) {
    if (GetCookie("Member_ID")=="") {
        Response.Redirect("/MembersLogin.aspx", true);
    }
}

The first if statement checks to see if a Kentico admin session is set. If it isn't, then the code inside the if is executed. This is the code for managing the members area of the site. Now this template can be worked with inside the Kentico admin without redirecting to the login page.