Jas*_*ord 12 c# azure-active-directory blazor-server-side .net-5
I'm successfully signing in and out using Azure AD B2C in a Blazor Server app, but it's not clear to me the proper way to define the SignedOut page. This question seems to be more applicable to Microsoft.Identity.Web.UI, because this SignedOut page seems to be hardcoded to a very generic SignedOut.cshtml:
Signed out
You have successfully signed out.
The documentation seems to indicate this can be changed, but it does not say how exactly.
From the documentation: "By default, the logout URL displays the signed-out view page SignedOut.cshtml.cs. This page is also provided as part of MIcrosoft.Identity.Web."
Given I'm writing a Blazor app, I tried creating a SignedOut.razor component, but that did not override it:
@page "/MicrosoftIdentity/Account/SignedOut"
这是来自Microsoft.Identity.Web.UI的来源。如您所见,它是硬编码的。
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);
    }
}
Jas*_*ord 14
Microsoft.Identity.Web v1.9
Updated: Here's my preferred method
只需将其添加到您的startup.cs中的Configure下即可。在这里,我刚刚重定向到我的主页,但如果您愿意,您可以重定向到您自己的自定义注销页面。
app.UseRewriter(
new RewriteOptions().Add(
    context =>
    {
        if (context.HttpContext.Request.Path == "/MicrosoftIdentity/Account/SignedOut")
        {
            context.HttpContext.Response.Redirect("/");
        }
    }));
方法#2
在写问题时,我确实找到了一种非常简单的方法。这似乎仍然很奇怪,这是预期的方式,所以请随意改进或添加更好的答案。我怀疑新版本的出现会让这变得更容易。
因为 Microsoft.Identity.Web.UI 是可重用类库 (RCL), any page can be overridden just by adding it to your web app in the same location.
正如您所看到的,我几乎通过创建自己的 SignedOut.razor 页面并为其提供与 URL 相同的路径来完成此任务。这是行不通的,因为它是一个 razor 组件,并且它必须匹配源中的路径,而不是 Web 应用程序中的 URL。
值得庆幸的是它是开源的。我必须找到这里的路径,因为它对我来说并不明显。 https://github.com/AzureAD/microsoft-identity-web
因此,这是您在项目中需要的正确路径,也是我能找到的最佳答案,它正在努力为您自己提供一个真正的 SignedOut 页面。我想如果您不想要“注销”页面,则必须在此处添加重定向。
区域/MicrosoftIdentity/Pages/Account/SignedOut.cshtml
| 归档时间: | 
 | 
| 查看次数: | 4523 次 | 
| 最近记录: |