ASP.NET core, change default redirect for unauthorized

前端 未结 7 837
抹茶落季
抹茶落季 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:07

    Since asp.net core 2.0 if you use cookies without Identity:

    app.UseAuthentication();
    
    // If you don't want the cookie to be automatically authenticated and assigned HttpContext.User, 
    // remove the CookieAuthenticationDefaults.AuthenticationScheme parameter passed to AddAuthentication.
    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(options => 
        {
            options.LoginPath = "/Account/LogIn";
            options.LogoutPath = "/Account/LogOff";
        });
    

    source

提交回复
热议问题