c# - 无法使用 C# 删除 cookie
问题描述
我的浏览器中有两个 cookie 在登录期间由 IDS4 放置在那里。我需要删除它们。未能通过退出来摆脱它们(无论出于何种原因,尽管有文档),我决定应用一个实用的解决方法并手动删除它们。看来那些是硬饼干。他们两个人...
我试图像这样摆脱它们 -以建议的所有可用模式为目标。
await HttpContext.SignOutAsync("Identity.Application");
await HttpContext.SignOutAsync("Identity.External");
await HttpContext.SignOutAsync("Identity.TwoFactorRememberMe");
await HttpContext.SignOutAsync("Identity.TwoFactorUserId");
await HttpContext.SignOutAsync("idsrv");
await HttpContext.SignOutAsync("idsrv.external");
我试图按照这里的建议通过明确的打击来杀死他们。不过,显然这不是饼干碎的方式。
Response.Cookies.Delete(".AspNetCore.Identity.Application");
Response.Cookies.Delete("idsrv.session");
没有什么能抹去他们。当然,当我重新启动浏览器时,它们确实会消失,但我需要它们在没有这种措施的情况下消失(另外,如果我要重新启动浏览器,我不需要注销用户,因为它们无论如何都会消失)。
我已经看到了调用的建议,HttpContext.Current
但这与我的控制器中的调用相同HttpContext
(根据this)。有人谈论,Session.Abandon
但在我的上下文中我没有看到那个领域。这个具体问题似乎存在一些问题,但我不知道 IDS4 团队是否仍未解决这些问题。
编辑
public async Task<IActionResult> LogOut([FromQuery] string logoutId)
{
LogoutRequest context = await InteractionService.GetLogoutContextAsync(logoutId);
bool? isLoggedIn = User?.Identity.IsAuthenticated;
isLoggedIn |= User.IsAuthenticated();
await HttpContext.SignOutAsync();
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
//Response.Cookies.Delete("idsrv.session");
var output = new
{
authenticated = isLoggedIn,
clientId = context.ClientId,
sessionId = context.SessionId,
redirect = context.PostLogoutRedirectUri,
sub = context.SubjectId
};
return Ok(output);
// return SignOut();
}
解决方案
执行注销时,不应从操作方法返回任何内容,因为 SignOutAsync 会生成自己的“响应”。我就是这样做的:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Logout()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
//Important, this method should never return anything.
}
推荐阅读
- c# - Pip 安装的软件包,它们在物理上指向什么?(用于 C# 中的 IronPython)
- r - 如何进行左连接,其中从“数据 B”中获取的行与 id 所在的行不同?
- c# - OrderByDescending 引发 SqlNullValueException
- java - 如何修复 gradle build error 配置根项目时出现问题?
- python - 列表和 sys.getsizeof 不一致
- php - register_taxonomy 不创建用户分类
- ravendb - 乌鸦数据库。过滤考虑建议的文档
- python - 如何将 CSV 读取到 pandas 并获取一个单元格的值
- acumatica - Save.Press() 和 Actions.PressSave() 有什么区别?
- python - 如何根据枚举数合并两个列表?