c# - asp.net中如何删除cookies

标签 c# .net asp.net

我想知道我们能否从 cookie 集合中删除我们在 asp.net 网站中创建的 cookie。我尝试并找到过期逻辑。它有效,但它显示在浏览器 cookie 中。

 Response.Cookies["UserID"].Expires = DateTime.Now.AddDays(-1);

是否有任何其他方法可以让我们从集合中删除 cookie,这样它就不会显示在浏览器 cookie 中。

请帮我解决这个问题。提前致谢。

最佳答案

来自documentation :

You cannot directly delete a cookie on a user's computer. However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date. The next time a user makes a request to a page within the domain or path that set the cookie, the browser will determine that the cookie has expired and remove it.

因此,您的策略是正确的,一旦收到响应,cookie 就应该从浏览器中消失。

关于c# - asp.net中如何删除cookies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6580390/

相关文章:

c# - MVC6 - 如果(复选框勾选)则删除线

c# - Asp.Net Core 中间件中的重定向不呈现目标页面

c# - 是否有必要将XML文件部署到类库中?

c# - WPF Prism + 现有 WPF 应用程序

.net - 在包/命名空间级别添加 .NET 源文档以使用 Doxygen 进行处理

c# - 将 XML 反序列化为对象时缺少子节点

.net - 如何在 Visible false 的页面加载时停止 UC 的执行

c# - 根据变量交换图像

c# - 服务引用错误 : Failed to generate code for the service reference

c# - 捆绑和缩小错误