0
votes

I'm having problems with my asp.net 4.0 Web Forms application not allowing anonymous access to landing page.

My problem is the following

  • If I access the site using URL "localhost/website/default.aspx", the default page is shown. When I click on the login button on the page, the users is logged in as expected.
  • If I access the site using URL "localhost/website", the user is taken directly to the login page. The expected behavior is that the "default.aspx" page will be displayed.

I'm testing on Windows 7/64 using VS2010. My web.config section looks like

<authentication mode="Forms">
  <forms name=".xxxxADAuthCookie" loginUrl="~/Login.aspx" timeout="45"
         defaultUrl="~/secure/Default.aspx" slidingExpiration="true" />
</authentication>
<membership defaultProvider="MyADMembershipProvider">
  <providers>
    <clear />
    <add attributeMapUsername="sAMAccountName" name="MyADMembershipProvider"
         type="xxxxx.xxxxxxFormsAuthenticationMembershipProvider" />
  </providers>
</membership>
<authorization>
  <deny users="?" />
  <allow users="*" />
</authorization>
  <location path="default.aspx">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>
  </location>
2
Make sure that default.aspx is at the top of your default document list. - Erik Funkenbusch
Do you want to access the default.aspx before log in? - Angus Chung
Yes. That is what the users want. - photo_tom
hi @photo_tom , is it works? - Angus Chung

2 Answers

0
votes

Check your Web.config: defaultUrl="~/secure/Default.aspx" The "/secure/" folder not mentioned in the hierarchy you described above.

Another option: try to force default routing in Global.asax.cs (something like this:)

    routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "website", action = "default", id = UrlParameter.Optional } 
0
votes

I think that you can set your loginUrl=defaultUrl.

<forms name=".xxxxADAuthCookie" loginUrl="~/secure/Default.aspx" timeout="45"
     defaultUrl="~/secure/Default.aspx" slidingExpiration="true" />


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

Try it again.