asp.net-core - 如何覆盖注销后重定向网址
问题描述
我正在使用 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。
解决方案
您忘记在 URL 前加上 / 不是错字吗?
喜欢
RedirectUri = "/Account/AccessDenied"
代替
RedirectUri = "Account/AccessDenied"
推荐阅读
- c - 将并行进程的结果添加到共享内存
- c - 在 C 中修改时间函数
- reactjs - 试图运行 webpack 以获取 bundle.js 文件时卡住了
- python - Python TCP 套接字服务 %100 CPU 使用率
- python - 如何在二进制图像中随机拾取非零像素的位置?
- python - 为什么调用 Python 的“魔术方法”不像对应的运算符那样进行类型转换?
- python - Python Pandas - 在所有列的单元格中搜索正则表达式匹配
- java - 测试 LITTLE_ENDIAN 和 BIG_ENDIAN 方案
- java - 如何显示我自己的 FileNotFoundException 消息
- networkx - 如何删除networkx中的随机边?