清除cookie

二次信任 提交于 2020-03-24 10:43:58


    private static void DetelteAllCookies(string domain)
    {
        if (HttpContext.Current.Request.Cookies["userToken"] == null)
        {
            string cookieName;
            int limit = HttpContext.Current.Request.Cookies.Count;
            for (int i = 0; i < limit; i++)
            {
                cookieName = HttpContext.Current.Request.Cookies[i].Name;
                HttpContext.Current.Response.Cookies.Remove(cookieName);
                HttpContext.Current.Response.Cookies[cookieName].Domain = domain;
                HttpContext.Current.Response.Cookies[cookieName].Expires = DateTime.Now.AddDays(-1);
                HttpContext.Current.Response.Cookies[cookieName].Value = null;
            }
        }
    }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!