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
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
