ASP Identity in MVC6 - Login Path property not wor

2020-03-01 09:07发布

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?

2条回答
一夜七次
2楼-- · 2020-03-01 09:22

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.

查看更多
Explosion°爆炸
3楼-- · 2020-03-01 09:39

For .NET Core -

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

works with Token auth too

查看更多
登录 后发表回答