Search code examples
asp.netforms-authentication

Allowing anonymous access to default page


My ASP.NET Forms 4.0 site is running with forms authentication. By default unauthorized users are denied, and then I allow access to certain pages. I have a problem allowing access to the default url: http:/example.com. I have this entry in web.config that defines default page:

<defaultDocument>
    <files>
        <clear/>
        <add value="default.aspx" />
    </files>
</defaultDocument>

and I have this location override:

<location path="default.aspx">
    <system.web>
        <authorization>
            <allow users="?"/>
        </authorization>
    </system.web>
</location>

It works OK when I go to the full url: http://example.com/default.aspx, but redirects to the login page if I go to http://example.com

Any ideas what am I doing wrong?


Solution

  • I just found answer in a response (by Dmitry) to a similar question here in SO: Forms Authentication Ignoring Default Document:

    In Global.asax, method: Application_BeginRequest, place the following:

    if (Request.AppRelativeCurrentExecutionFilePath == "~/")
        HttpContext.Current.RewritePath("default.aspx");
    

    Worked like charm!