ASP.NET - stops being redirected to the login page if it appears on the registration page

Hope it's easy. I have a pretty simple ASP.NET application (framework version 2) that uses a user table to validate a user. In any case, I have two pages, login and registration. You can guess what the goal is. It is assumed that the user can request registration by clicking on the registration link - this is a form with a submit button that calls some database calls to find out if the user exists, etc. The login page uses authentication to verify. I use forms authentication - this is in my web.config:

    <authentication mode="Forms">
        <forms loginUrl="logon.aspx" name="adAuthCookie" timeout="30" path="/" defaultUrl="~/logon.aspx">
        </forms>
    </authentication>

Each time I make an http call on the registration page (i.e. by typing http: //localhost/registration.aspx - it is redirected to the login page.

In the global.asax.cs file there is this - authentication. I want to disable this check if the requesting page is a registration page, since users do not need to authenticate to visit this page. Any ideas how to do this?

void Application_AuthenticateRequest(object sender, EventArgs e)
{
    string cookieName = FormsAuthentication.FormsCookieName;
    HttpCookie authCookie = Context.Request.Cookies[cookieName];

    if (null == authCookie)
    {
        //There is no authentication cookie.
        return; // right here it will return null then redirect to login.aspx
    }
    FormsAuthenticationTicket authTicket = null;
    try
    {
        authTicket = FormsAuthentication.Decrypt(authCookie.Value);
    }
    catch (Exception ex)
    {
        //Write the exception to the Event Log.
        return;
    }
    if (null == authTicket)
    {
        //Cookie failed to decrypt.
        return;
    }
    //When the ticket was created, the UserData property was assigned a
    //pipe-delimited string of group names.
    string[] groups = authTicket.UserData.Split(new char[] { '|' });
    //Create an Identity.
    GenericIdentity id = new GenericIdentity(authTicket.Name, "LdapAuthentication");
    //This principal flows throughout the request.
    GenericPrincipal principal = new GenericPrincipal(id, groups);
    Context.User = principal;
}
+3
source share
2 answers

You can configure access to your web.config. Here is an example of what I will do:

<location path="register.aspx"> //path here is path to your register.aspx
    <system.web>
        <authorization>
            <allow users="*"/> // this will allow access to everyone to register.aspx
        </authorization>
    </system.web>
</location>
+2
source

this may help you install it using web.config

 <location path="registration.aspx">
            <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
            </system.web>
            </location>

Additional Information MSDN Link http://support.microsoft.com/kb/316871

+2
source

All Articles