MVC 5 - authorisation blues with forms authentication

60 views Asked by At

With WebForms I don't have a problem with forms authentication, but it's giving me grief in MVC 5

Added Secure to Areas, then Landing and Login

MVC areas

In the main web.config file added this under system.web (also variants like ~/Secure/Login)

 <authentication mode="Forms">
  <forms loginUrl="Secure/Login" />
</authentication> 

And sub web.config file (under secure) this (sorry indent wouldn't work so used code snippet)

<location path="">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="Login">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>
  </location>​

But for some reason it doesn't work.

1

There are 1 answers

0
gchq On BEST ANSWER

Added this to Startup.Auth and it works perfectly

app.UseCookieAuthentication(New CookieAuthenticationOptions() With {.LoginPath = New PathString("/Secure/Login")})