日期:2014-05-18  浏览次数:20463 次

刺手问题:求助关于删除Cookie.Domain的问题!删除cookies时无效。急急急!
目的:登录时,add或set一个cookies,退出时,删除这个cookies
问题:在不添加domain时,用cookies完成登录和退出是OK的,
   但加了domain后,删除cookies就不管用了。

=======================================================
例如:cookies名称:MyCookies;domain域:abc.com 
登录部分代码如下:
=======================================================
HttpCookie   MyCo   =   HttpContext.Current.Request.Cookies[ "MyCookies "];
MyCo.Values.Add( "xxxxx ", "xxxxxxx ");
........
MyCo.Domain =   "abc.com ";
MyCo.Expires =   now.AddHours(24);
HttpContext.Current.Response.Cookies.Add(MyCo);
=======================================================


登录成功,cookies也能在多个二级域名下共享使用。
但退出,就不灵了。退出部分代码如下:
=======================================================
Response.Cookies[ "MyCookies "].Domain   =   " ";
Response.Cookies[ "MyCookies "].Domain   =   null;
Response.Cookies[ "MyCookies "].Values.Clear();
Response.Cookies.Remove( "MyCookies ");
Response.Cookies.Clear();
Response.Cookies[ "MyCookies "].Expires   =   DateTime.Now.AddHours(-24);

请问有什么解决办法么,谢谢!


------解决方案--------------------
删除时:
HttpCookie cookie = Request.Cookies[ "MyCookies "];
Response.Cookies[ "MyCookies "].Expires = DateTime.Now.AddHours(-24);
Response.Cookies[ "MyCookies "].Domain = "abc.com ";//要和上面的一样
Response.Cookies.Add(cookie);