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
.
source to share
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);
}
source to share