我想知道我们能否从 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/