Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: AuthorizeAttribute on default page

The default controller in my ASP.NET MVC project is decorated with the [Authorize] attribute. When I deploy the website on my development machine and access the website, I am redirected to the login page (defined in forms loginUrl section of the Web.Config). Result: everything works as expected.

When I publish the website on our production server (Windows Server 2008, IIS 7, DefaultAppPool) and access the website, the expected address shows in the address bar (/Account/LogOn?ReturnUrl=*my_expected_return_url*), but the page displays "You do not have permission to view this directory or page." instead of the login page. If I remove the [Authorize] attribute on the default controller/action, the page displays correctly.

My Web.Config file:

sessionState mode="InProc" timeout="30"  
     authentication mode="Forms"  
        forms loginUrl="~/Account/LogOn" timeout="2880"
like image 455
Alex B Avatar asked Nov 14 '22 11:11

Alex B


1 Answers

Do you have a section in your web.config to explicitly allow non-authorised users to access the ~/Account/LogOn page?

<configuration>
  <location path="~/Account/LogOn">
    <system.web>
      <authorization>
        <allow users="*" />
        <allow users="?" />
      </authorization>
    </system.web>
  </location>
</configuration>
like image 65
Andrew Avatar answered Dec 06 '22 05:12

Andrew