c# - 使用 Microsoft.AspNetCore.Authentication.AzureADB2C.UI 时如何覆盖/替换错误页面处理?

标签 c# azure asp.net-core azure-active-directory azure-ad-b2c

我在 ASP.Net Core 2.2 MVC Web 应用程序中使用 Azure AD B2C .Net core Microsoft.AspNetCore.Authentication.AzureADB2C.UI 库(使用 NuGet 安装)。

我希望能够更改错误页面,但它会忽略任何自定义或开发人员模式错误页面。

有谁知道我如何覆盖错误处理和/或该库的任何其他页面?

这是针对任何 Azure B2C 错误返回的页面 (github)。 https://github.com/aspnet/AspNetCore/blob/master/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Areas/AzureADB2C/Pages/Account/Error.cshtml

我创建了一个自定义错误页面,并在启动中包含以下内容。其他所有内容都使用此自定义页面或默认开发人员异常页面,具体取决于模式。

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();
}

最佳答案

将其放入 Startup.Configure() 方法中:

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

重定向到您想要的任何页面。

关于c# - 使用 Microsoft.AspNetCore.Authentication.AzureADB2C.UI 时如何覆盖/替换错误页面处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56391996/

相关文章:

.net - 每个 Web 角色多个应用程序

azure - 加密 secret 值时出错 - 操作返回无效状态代码 'BadRequest'

angular - ASP.net Core 中的加密和 Angular 中的解密

javascript - 无法使用 jquery 删除文本框

c# - 在 WPF 中使用 ObservableCollection<Dictionary<String, Object>> 作为 DataGrid Itemsource

c# - 如何从 StackOverflow API *creation_date* 字段中检索实际日期?

c# - Cosmos DB 中是否支持使用 OData 进行分页?

c# - C# 中的字节与短与整数(以及无符号变体)?

java - Microsoft Azure IoT 中心 (java) 发送消息后通知 "Lost connection to the server. Reconnecting 0 time."

asp.net-mvc - 如何通过 netcore3.1 中的环境变量更改 Kestrel (AspNetCore) 监听端口