Simone Spagna
Simone Spagna

Reputation: 636

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.

Upvotes: 0

Views: 1231

Answers (2)

TanvirArjel
TanvirArjel

Reputation: 32069

You can simply do as follows:

public void ConfigureServices(IServiceCollection services)
{

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

    });

}

Upvotes: 1

fingers10
fingers10

Reputation: 7957

Try Configuring IdentityOptions in Startup as below,

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

Upvotes: 1

Related Questions