问题
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