ASP.NET core, change default redirect for unauthorized

前端 未结 7 807
抹茶落季
抹茶落季 2020-12-05 09:55

I am attempting to redirect to a different login url in ASP.NET MVC6

My account controller login method has a Route attribute to change the url.

相关标签:
7条回答
  • 2020-12-05 10:27

    If you check UseIdentity extension method here you will notice that it is using IdentityOptions not CookieAuthenticationOptions, so instead you must configure IdentityOptions:

    services.Configure<IdentityOptions>(opt =>
    {
        opt.Cookies.ApplicationCookie.LoginPath = new PathString("/login");
    });
    

    Edit

    For asp.net core 2.0: Identity cookie options are no longer part of IdentityOptions. Check mxmissile's answer.

    0 讨论(0)
提交回复
热议问题