【问题标题】:logout redirect url for microsoft identity provider and .net core (5) MVC微软身份提供者和 .net 核心的注销重定向 url (5) MVC
【发布时间】:2025-12-14 13:05:02
【问题描述】:

我为我的 mvc azure 应用程序(.net core 5)实现了登录/注销机制,登录和注销方法按预期工作,但有一个我无法解决的问题。当用户注销时,我希望他们被重定向到我的应用程序中的特定页面,而不是中间件提供的默认 SignedOut.cshtml 页面。从我的应用程序的 .net 核心代码(我可以找到)中,似乎没有一种直接的方法可以做到这一点。在谷歌搜索该问题后,我尝试了一些建议,但似乎没有任何效果。这就是我在 startup.cs 的 ConfigureServices 方法中实现 MicrosoftIdentityWebAppAuthentication 的方式

services.AddMicrosoftIdentityWebAppAuthentication(Configuration);

        services.AddControllersWithViews(options =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            options.Filters.Add(new AuthorizeFilter(policy));
        }).AddMicrosoftIdentityUI();

每当我注销时,我总是会转到 Microsoft 提供的默认注销页面 (SignedOut.cshtml),在注销过程完成并重定向到我选择的页面后,肯定必须有一种简单的方法来覆盖此行为,在我的应用程序中。我在我的应用程序的 appsettings.json 文件中有这个

"CallbackPath": "/signin-oidc",
"SignedOutCallbackPath ": "/signout-callback-oidc"

有没有人设法做到这一点?我真的很感激一些建议

【问题讨论】:

  • 你试过了吗:services.ConfigureApplicationCookie(options => { options.LogoutPath = $"/account/logout"; });
  • 我做了,但完全一样。我假设我需要使用这种方法创建我自己的帐户控制器? (不使用 .net core 中的默认值)

标签: c# asp.net-mvc redirect .net-core microsoft-identity-platform


【解决方案1】:

您可以通过重写 URL 来实现。试试下面的

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

参考:http://5.9.10.113/68376160/how-do-i-redirect-to-my-own-custom-logout-page-after-the-logout-process-has-comp

【讨论】:

    最近更新 更多