0

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.

4
  • You are using [Authorize] on your classes? Commented Sep 28, 2019 at 19:45
  • Are you using ASP.NET Core Identity or something else? Commented Sep 28, 2019 at 20:09
  • @GuilhermeMartin yes I'm using [Authorize]. Commented Sep 29, 2019 at 2:00
  • @KirkLarkin : yes, I'm using ASP.NET CORE Identity. Commented Sep 29, 2019 at 2:01

2 Answers 2

1

You can simply do as follows:

public void ConfigureServices(IServiceCollection services)
{

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

    });

}
Sign up to request clarification or add additional context in comments.

Comments

1

Try Configuring IdentityOptions in Startup as below,

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

1 Comment

Seems not to find a definition for Cookies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.