ASP Identity in MVC6 - Login Path property not wor

2020-03-01 08:41发布

问题:

After updating from beta 5 to beta 8 I can't set my custom login path in cookie authentication options.

services.AddCookieAuthentication(config =>
{
    config.LoginPath = "/Auth/Login";
    //or
    //config.LoginPath = new Microsoft.AspNet.Http.PathString("Auth/Login");
});

This value is completely ignored. Still gets redirected to the default '/Account/Login'. Is there any other options to set this path?

回答1:

It seems that now you should do this a bit differently (worked for me):

services.Configure<IdentityOptions>(options=>
{
    options.Cookies.ApplicationCookie.LoginPath = new Microsoft.AspNet.Http.PathString("/Auth/Login");
});

From here.



回答2:

For .NET Core -

services.Configure<IdentityOptions>(options=>
options.Cookies.ApplicationCookie.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Auth/Login");
});

works with Token auth too