删除Cookie上点击退出 [英] Delete cookie on clicking sign out
本文介绍了删除Cookie上点击退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是code以下,如何读取另一页txtusername价值,以及如何删除cookie,当我点击登出(code代表登出)创建的cookie。我是新来编程,请帮助。
字符串cookiestr;
CK的HttpCookie;
TKT =新的FormsAuthenticationTicket(1,txtUserName.Value,DateTime.Now,
DateTime.Now.AddMinutes(30),chkPersistCookie.Checked,自定义数据);
cookiestr = FormsAuthentication.Encrypt(TKT); CK =新的HttpCookie(FormsAuthentication.FormsCookieName,cookiestr);
如果(chkPersistCookie.Checked)
ck.Expires = tkt.Expiration;
ck.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(CK);
解决方案
您永远不应该存储的密码的作为的饼干的。这是一个非常大的安全威胁。要删除一个cookie,你真的只需要修改和终止它。你真的不能将其删除,即从用户的硬盘中删除。看看这个文档。
下面是一个例子:
的HttpCookie aCookie;
串cookieName;
INT极限= Request.Cookies.Count;
的for(int i = 0; I<限制;我++)
{
cookieName = Request.Cookies时[I] .Name点;
aCookie =新的HttpCookie(cookieName);
aCookie.Expires = DateTime.Now.AddDays(-1); //使它昨天到期
Response.Cookies.Add(aCookie); //覆盖它
}
I am creating the cookie using the code below, How to read the txtusername value in another page and how to delete the cookie when I click sign out(code for sign out). I am new to programming please help.
string cookiestr;
HttpCookie ck;
tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now,
DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
if (chkPersistCookie.Checked)
ck.Expires = tkt.Expiration;
ck.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(ck);
解决方案
You should never store password as a cookie. That's a very big security threat. To delete a cookie, you really just need to modify and expire it. You can't really delete it, i.e. remove it from the user's disk. Check out this documentation.
Here is a sample:
HttpCookie aCookie;
string cookieName;
int limit = Request.Cookies.Count;
for (int i=0; i<limit; i++)
{
cookieName = Request.Cookies[i].Name;
aCookie = new HttpCookie(cookieName);
aCookie.Expires = DateTime.Now.AddDays(-1); // make it expire yesterday
Response.Cookies.Add(aCookie); // overwrite it
}
这篇关于删除Cookie上点击退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文