简体   繁体   English

如何删除 asp.net 中的 cookies

[英]how to delete cookies in asp.net

I would like to know can we delete cookie from cookies collection what we have created in asp.net website.I tried & find Expiration Logic.It works but it shows in browser cookie.我想知道我们能否从 cookies 集合中删除我们在 asp.net 网站中创建的 cookie。我尝试并找到了过期逻辑。它有效,但它显示在浏览器 cookie 中。

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

Is there any other way by this we can delete cookies from collection so it will not show in browser cookies.还有其他方法吗?我们可以从集合中删除 cookies,这样它就不会显示在浏览器 cookies 中。

Please help me to solve the issue.Thanks in advance.请帮我解决问题。在此先感谢。

From the documentation :文档中:

You cannot directly delete a cookie on a user's computer.您不能直接删除用户计算机上的 cookie。 However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date.但是,您可以通过将 cookie 的到期日期设置为过去的日期来指示用户的浏览器删除 cookie。 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 的域或路径中的页面发出请求时,浏览器将确定 cookie 已过期并将其删除。

So, your strategy is the right one, and the cookie should disappear from the browser once the response is received.因此,您的策略是正确的,一旦收到响应,cookie 应该从浏览器中消失。

I'm not sure you can delete the cookie since you don't have access to delete anything on the client computer.我不确定您是否可以删除 cookie,因为您无权删除客户端计算机上的任何内容。 All you can do is basically what you are doing, that is invalidating the cookie for your application.您所能做的基本上就是您正在做的事情,即使您的应用程序的 cookie 无效。 I think it is up to the client software to decide if the cookie should be deleted or not, all you can do is set the timestamp as you are doing and that means that you will no longer accept that cookie.我认为由客户端软件决定是否应该删除 cookie,您所能做的就是设置时间戳,这意味着您将不再接受该 cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM