首页 > 解决方案 > 如何覆盖注销后重定向网址

问题描述

我正在使用 IdentityServer3,并且我将 ASP.NET Core 作为客户端应用程序。

这是我的 LoggOff 操作方法

    [HttpPost]
    public async Task LogOff()
    {
        await Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.SignOutAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme);
        await Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.SignOutAsync(HttpContext, OpenIdConnectDefaults.AuthenticationScheme);
    }

当用户注销时,我在提琴手中看到以下重定向

   GET /identity/connect/endsession?post_logout_redirect_uri=https%3A%2F%2Flocalhost%3A44352%2Fsignout-callback-oidc&state=XXXXXX&x-client-SKU=XXXXXX&x-client-ver=5.3.0.0 HTTP/1.1

   GET /identity/logout?id=XXXXXXXXXX 

   GET /identity/connect/endsessioncallback?sid=XXXXXXX

最终在浏览器 url 中设置为/identity/logout?id=XXXXXXXXXX. 这些是身份服务器的 URL,而不是客户端应用程序 URL。

LogOff当注销按钮调用操作方法时,这按预期工作。

现在我有一个要求。当用户转到AccessDenied页面时,我想先注销用户,然后重定向到AccessDenied查看。该AccessDenied页面位于 ClientAppliction 中。所以我有另一个调用 SingnOut 并设置的动作方法RedirectUri

    [HttpGet]
    public async Task AccessDenied()
    {
        await Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.SignOutAsync(HttpContext, CookieAuthenticationDefaults.AuthenticationScheme);
        await Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.SignOutAsync(HttpContext,
            OpenIdConnectDefaults.AuthenticationScheme,
            new Microsoft.AspNetCore.Authentication.AuthenticationProperties()
            {
                RedirectUri = "Account/AccessDenied"
            });
    }
    

这是行不通的。用户仍然去identity/logout而不是AccessDenied。看起来它没有设置注销后重定向 uri。

标签: asp.net-coreopenid-connectidentityserver3

解决方案


您忘记在 URL 前加上 / 不是错字吗?

喜欢

RedirectUri = "/Account/AccessDenied"

代替

RedirectUri = "Account/AccessDenied"

推荐阅读