admin管理员组文章数量:1024016
How can I remove all my site's cookies from the client, either in ASP.NET/C# or JavaScript? Basically I would like to click a button or link on the page and have it clear all the cookies for the site. I don't need to know the name of every cookie, do I?
How can I remove all my site's cookies from the client, either in ASP.NET/C# or JavaScript? Basically I would like to click a button or link on the page and have it clear all the cookies for the site. I don't need to know the name of every cookie, do I?
Share Improve this question asked Jul 8, 2010 at 21:37 JamesBrownIsDeadJamesBrownIsDead 3551 gold badge5 silver badges9 bronze badges2 Answers
Reset to default 4foreach (string key in Request.Cookies.AllKeys)
{
HttpCookie cookie = new HttpCookie(key);
cookie.Expires = DateTime.UtcNow.AddDays(-7);
Response.Cookies.Add(cookie);
}
As I wrote before to @mwilson, you cannot directly delete a cookie on a user's puter. However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date.
To delete all cookies just browse the Response.Cookies collection with a foreach loop and replace the date of each cookie with a past date.
Check this page if you need some help:
How can I remove all my site's cookies from the client, either in ASP.NET/C# or JavaScript? Basically I would like to click a button or link on the page and have it clear all the cookies for the site. I don't need to know the name of every cookie, do I?
How can I remove all my site's cookies from the client, either in ASP.NET/C# or JavaScript? Basically I would like to click a button or link on the page and have it clear all the cookies for the site. I don't need to know the name of every cookie, do I?
Share Improve this question asked Jul 8, 2010 at 21:37 JamesBrownIsDeadJamesBrownIsDead 3551 gold badge5 silver badges9 bronze badges2 Answers
Reset to default 4foreach (string key in Request.Cookies.AllKeys)
{
HttpCookie cookie = new HttpCookie(key);
cookie.Expires = DateTime.UtcNow.AddDays(-7);
Response.Cookies.Add(cookie);
}
As I wrote before to @mwilson, you cannot directly delete a cookie on a user's puter. However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date.
To delete all cookies just browse the Response.Cookies collection with a foreach loop and replace the date of each cookie with a past date.
Check this page if you need some help:
本文标签: ASPNETJavaScript Remove all cookiesStack Overflow
版权声明:本文标题:ASP.NETJavaScript: Remove all cookies - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745551209a2155641.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论