ASP.NET CORE 2.2 authorization error redirect page

和自甴很熟 提交于 2021-01-29 13:20:28

问题


I wrote a Wep Application ASP NET CORE 2.2 in c# which uses the authorization. They work properly. When access is denied now the url is rewritten for example as follows:

https://ebbwebdev.azurewebsites.net/Account/AccessDenied?ReturnUrl=%2FTelemetries

and the page displayed is Error 404.

I'm using ASP.NET Core Identity.

How can I redirect access denied to a custom page?

Thanks for your cooperation.


回答1:


You can simply do as follows:

public void ConfigureServices(IServiceCollection services)
{

    services.ConfigureApplicationCookie(options =>
    {
        options.AccessDeniedPath = "/YourCustomAccessDeniedPath";

    });

}



回答2:


Try Configuring IdentityOptions in Startup as below,

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


来源:https://stackoverflow.com/questions/58149592/asp-net-core-2-2-authorization-error-redirect-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!