ASP.NET core, change default redirect for unauthorized

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

    You may also want to try using StatusCodePages:

    app.UseStatusCodePages(async context => {
        var response = context.HttpContext.Response;
    
        if (response.StatusCode == (int)HttpStatusCode.Unauthorized || 
            response.StatusCode == (int)HttpStatusCode.Forbidden)
            response.Redirect("/Error/Unauthorized");
    });
    

提交回复
热议问题