我正在尝试自定义Azure B2C应用程序错误(AADB2C99002)的帐户错误,但是,它总是重定向到https:///MicrosoftIdentity/Account/Error,而我的帐户错误页面应该是https:///Home/错误 我尝试了这个document,并禁用了开发模式,但没有任何效果。请指教。
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/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();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
错误路径的默认值为
new PathString("/MicrosoftIdentity/Account/Error")
您可以使用新的路径值覆盖此路径值,您可以为 adb2c 错误路径设置任何自定义错误页面。有 mergeOptions 可用于更新此值。要更新路径,请按照以下步骤操作
使用 adb2c 进行配置时,添加 Error Path 属性并在 appsettings.json
中设置路径值,如下所示 "AzureAdB2C": {
"Instance": "https://test.b2clogin.com",
"ClientId": "clientId",
"ClientSecret": "ClientSecret",
"Domain": "test.onmicrosoft.com",
"SignedOutCallbackPath": "/signout/SUSI_1",
"SignUpSignInPolicyId": "SUSI_1",
"ErrorPath": "/Home/Error"
},
在Program.cs中传递此配置
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration, Constants.AzureAdB2C)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph(builder.Configuration.GetSection("GraphApi"))
.AddInMemoryTokenCaches();
builder.Services.Configure<OpenIdConnectOptions>(builder.Configuration.GetSection("AzureAdB2C"));
注意:这里你会得到设置Error Path的属性,但是这个属性是私有设置的,所以你不能设置。