How to override / substitute Error Page handling when using the Microsoft.AspNetCore.Authentication.AzureADB2C.UI?

▼魔方 西西 提交于 2020-06-27 02:55:04

问题


I am using the Azure AD B2C .Net core Microsoft.AspNetCore.Authentication.AzureADB2C.UI library (installed using NuGet) in a ASP.Net Core 2.2 MVC Web App.

I would like to be able to change the Error page, however it ignores any custom or Developer mode error pages.

Does anyone know how I can override the error handling and/or any other pages of this library?

This is the page (github) that gets returned for any Azure B2C errors. https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Areas/AzureADB2C/Pages/Account/Error.cshtml

I have created a custom error page and have the following in my startup. Everything else uses either this custom page or the default developer exception page depending on mode.

if (env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}
else
{
    app.UseExceptionHandler("/Account/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

回答1:


Put this in your Startup.Configure() method:

app.UseRewriter(new RewriteOptions().Add(context =>
{
    if (context.HttpContext.Request.Path == "/AzureADB2C/Account/SignedOut")
    {
        context.HttpContext.Response.Redirect("/Home/SignedOut");
    }
}));

Redirect to whatever page you want.



来源:https://stackoverflow.com/questions/56391996/how-to-override-substitute-error-page-handling-when-using-the-microsoft-aspnet

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