ASP.NET MVC 5 (Visual Studio 2013 Preview) Change Login Address for [Authorize]

Hi guys, I started playing with ASP.NET MVC 5 preview and everything went well (I can only recommend it).

However I am wondering where can I set the Login-Url for the built-in [Authorize]

-Attribute. I have moved AccountController

to scope, so the path to the Login action is no longer /Account/Login

but MyArea/Account/Login

, which is ignored by the [Authorize]

-Attribute, which in turn means that whenever one navigates to a controller or action with the attribute set, one is redirected to the wrong path /Account/Login

.

+2


source to share


2 answers


Look web.config

for a section like this:

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

      



Change the value loginUrl

to point to the updated login page.

+9


source


When using the new OWIN forms authentication (as opposed to the old ASP.NET forms authentication) this is set in the class Startup

. In default templates, it is in App_Start/Startup.Auth.cs

the method ConfigureAuth

:



public void ConfigureAuth(IAppBuilder app)
{
   app.UseCookieAuthentication(new CookieAuthenticationOptions
   {
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
      LoginPath = new PathString("/Account/Login")
   });
   app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}

      

+15


source







All Articles