wucf2004的博客

asp.net和ajax
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

跨域删除cookie的问题

Posted on 2008-08-12 15:49  wucf2004  阅读(1344)  评论(0编辑  收藏  举报

//参考别人的方法

HttpCookie MyCo;
        string _strPageDomain="test.cn";
       if (_strPageDomain != null && _strPageDomain != "")
       {
           MyCo = HttpContext.Current.Request.Cookies["siteinfo"];
           if (System.Web.HttpContext.Current.Request.ServerVariables.ToString().IndexOf(_strPageDomain)>= 0 && MyCo != null)
           {
               MyCo.Domain = _strPageDomain;
               MyCo.Expires = DateTime.Now.AddHours(-24); //关键是这一句
               HttpContext.Current.Response.Cookies.Add(MyCo);
           }
       }
       else
       {
           MyCo = HttpContext.Current.Request.Cookies["siteinfo"];
           if (MyCo != null)
           {
               MyCo.Expires = DateTime.Now.AddHours(-48);                
               HttpContext.Current.Response.Cookies.Add(MyCo);
           }
       }