Can#39;t remove cookies using C#(无法使用C#删除Cookie)
问题描述
我的浏览器中有两个Cookie,在登录时IDS4放在那里。我要把它们取下来。由于无法通过注销来删除它们(无论出于什么原因,despite the docs),我决定应用一种实际的变通办法,并手动删除它们。这似乎是一块硬邦邦的饼干。其中两个...
我试图像这样摆脱它们--瞄准所有可用的架构as suggested。
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");
我试图通过显式命中proposed here来杀死他们。不过,很明显,饼干并不是这么碎的。
Response.Cookies.Delete(".AspNetCore.Identity.Application");
Response.Cookies.Delete("idsrv.session");
这些都不会抹去它们。当然,当我重新启动浏览器时,它们确实会消失,但我需要它们在没有该措施的情况下消失(此外,如果我要重新启动浏览器,我不需要注销用户,因为它们无论如何都会消失)。
我看到了调用HttpContext.Current的建议,但这与在我的控制器中简单地调用HttpContext相同(根据this)。有talk about Session.Abandon,但在我的上下文中看不到该字段。这个特定的问题似乎有some issues,但我不知道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会生成自己的&q;响应&q;。我是这样做的:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Logout()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
//Important, this method should never return anything.
}
这篇关于无法使用C#删除Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法使用C#删除Cookie
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
