现在的位置: 首页 > 综合 > 正文

跨域删除cookie的问题

2012年10月02日 ⁄ 综合 ⁄ 共 757字 ⁄ 字号 评论关闭

//参考别人的方法

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);
           }
       }

抱歉!评论已关闭.