简体   繁体   中英

ASP.NET CORE 2.2 authorization error redirect page

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.

Try Configuring IdentityOptions in Startup as below,

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

You can simply do as follows:

public void ConfigureServices(IServiceCollection services)
{

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

    });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM