Azure active directory 如何在Microsoft.Identity.Web中定义SignedOut页面?
我正在Blazor服务器应用程序中使用Azure AD B2C成功登录和注销,但我不清楚如何正确定义SignedOut页面。此问题似乎更适用于Microsoft.Identity.Web.UI,因为此SignedOut页面似乎是硬编码为非常通用的SignedOut.cshtml: 注销Azure active directory 如何在Microsoft.Identity.Web中定义SignedOut页面?,azure-active-directory,blazor-server-side,.net-5,Azure Active Directory,Blazor Server Side,.net 5,我正在Blazor服务器应用程序中使用Azure AD B2C成功登录和注销,但我不清楚如何正确定义SignedOut页面。此问题似乎更适用于Microsoft.Identity.Web.UI,因为此SignedOut页面似乎是硬编码为非常通用的SignedOut.cshtml: 注销您已成功注销 文件似乎表明这是可以改变的,但并没有具体说明如何改变 从: 默认情况下,注销URL显示已注销的视图页SignedOut.cshtml.cs。此页也是作为MIcrosoft.Identity.Web的一
您已成功注销 文件似乎表明这是可以改变的,但并没有具体说明如何改变 从: 默认情况下,注销URL显示已注销的视图页SignedOut.cshtml.cs。此页也是作为MIcrosoft.Identity.Web的一部分提供的 鉴于我正在编写Blazor应用程序,我尝试创建SignedOut.razor组件,但没有覆盖它:
@page "/MicrosoftIdentity/Account/SignedOut"
这里是来源。正如你所看到的,它是硬编码的
public IActionResult SignOut([FromRoute] string scheme)
{
if (AppServicesAuthenticationInformation.IsAppServicesAadAuthenticationEnabled)
{
return LocalRedirect(AppServicesAuthenticationInformation.LogoutUrl);
}
else
{
scheme ??= OpenIdConnectDefaults.AuthenticationScheme;
var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme);
return SignOut(
new AuthenticationProperties
{
RedirectUri = callbackUrl,
},
CookieAuthenticationDefaults.AuthenticationScheme,
scheme);
}
}
Microsoft.Identity.Web v1.9 更新:这是我的首选方法 只需将其添加到“配置”下的startup.cs。在这里,我刚刚重定向到我的主页,但如果您愿意,您可以重定向到自己的自定义注销页面
app.UseRewriter(
new RewriteOptions().Add(
context =>
{
if (context.HttpContext.Request.Path == "/MicrosoftIdentity/Account/SignedOut")
{
context.HttpContext.Response.Redirect("/");
}
}));
方法#2
在写问题的时候,我确实找到了一种非常简单的方法。这似乎仍然很奇怪,这是预期的方式,所以请随时改进或添加更好的答案。我怀疑新版本会使这更容易
由于Microsoft.Identity.Web.UI是一个,因此只需将任何页面添加到同一位置的Web应用程序中,即可覆盖该页面
如您所见,我几乎通过创建自己的SignedOut.razor页面并为其提供与URL相同的路径来实现这一点。这是行不通的,因为它是一个razor组件,它必须匹配源代码中的路径,而不是web应用程序中的URL
谢天谢地,它是开源的。我必须找到这条路,因为我看不清楚。
因此,这是您在项目中需要的正确路径,也是我能找到的最佳答案,即为您自己提供一个真正的登录页面。我想如果你不想要一个SignedOut页面,你必须在这里添加一个重定向
Areas/MicrosoftIdentity/Pages/Account/SignedOut.cshtml非常感谢!这就是我要找的。出于好奇,你找到了更优雅的吗?我的功能请求被拒绝并关闭了。你可以试着把它打开。由于Microsoft.Identity不是专门为Blazor设计的,因此他们认为没有必要。我更喜欢startup.cs中的重写方法。