如何清除饼干 [英] how to clear cookies
本文介绍了如何清除饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
注销后如何清除cookie
how to clear cookies after logout
推荐答案
以使浏览器转储cookie
您必须将Cookie设置为过去过期.
在LogOut事件中:
to get the browser to dump the cookies
you have to set the cookies to expire in the past.
In the LogOut event just :
if ((Request.Cookies("CookieName") != null))
{
Response.Cookies("CookieName").Expires = DateTime.Now.AddDays(-30);
}
在上面的AddDays中指定否.记住您在创建cookie时使用的内容.
有关更多信息,请参见: http://wiki.asp.net/page.aspx/372/login -through-cookies/ [ ^ ]
http://msdn.microsoft.com/en-us/library/ms178195.aspx [ ^ ]
In the above in AddDays Specify no. of days by keeping in mind what you you have used while creating cookie.
for more refer :http://wiki.asp.net/page.aspx/372/login-through-cookies/[^]
http://msdn.microsoft.com/en-us/library/ms178195.aspx[^]
你好朋友
删除cookie(从用户硬盘上物理删除它)是修改它的一种方式.您不能直接删除cookie,因为该cookie在用户的计算机上.但是,您可以让浏览器为您删除Cookie.该技术是使用与要删除的cookie相同的名称创建一个新cookie,但将cookie的到期日期设置为早于今天的日期.当浏览器检查cookie的到期时间时,浏览器将丢弃现在过时的cookie.以下代码示例显示了删除该应用程序可用的所有cookie的一种方法:
Hello friend
Deleting a cookie—physically removing it from the user''s hard disk—is a variation on modifying it. You cannot directly remove a cookie because the cookie is on the user''s computer. However, you can have the browser delete the cookie for you. The technique is to create a new cookie with the same name as the cookie to be deleted, but to set the cookie''s expiration to a date earlier than today. When the browser checks the cookie''s expiration, the browser will discard the now-outdated cookie. The following code example shows one way to delete all the cookies available to the application:
HttpCookie aCookie = default(HttpCookie);
int i = 0;
string cookieName = null;
int limit = Request.Cookies.Count - 1;
for (i = 0; i <= limit; i++) {
cookieName = Request.Cookies(i).Name;
aCookie = new HttpCookie(cookieName);
aCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(aCookie);
}
public static void ClearCookies()
{
if (HttpContext.Current.Request.Cookies["Users"] != null)
{
HttpCookie aCookie = HttpContext.Current.Request.Cookies["Users"];
aCookie.Expires = DateTime.Now.AddDays(-10);
aCookie.Value = "";
HttpContext.Current.Response.Cookies.Add(aCookie);
}
}
这篇关于如何清除饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文