asp.net 跨子域名域Session丢失问题

一、处理代码:

    //请求结束  重写SessionID
        protected void Application_EndRequest(object sender, EventArgs e)
        {
            //重置 ASP.NET_SessionId
            if (Request.Url.Host.Contains("localhost") == false)
            {
                //获取指定ID的cookie 对象,如果不存在则创建
                HttpCookie cookie = Response.Cookies.Get("ASP.NET_SessionId");
                if (cookie != null && !string.IsNullOrEmpty(cookie.Value))
                {
                    string host = Request.Url.Host;
                    host = host.Substring(host.IndexOf("."));
                    cookie.Domain = host;
                    cookie.Path = "/";
                    cookie.Value = cookie.Value;
                }
                else
                {
                    Response.Cookies.Remove("ASP.NET_SessionId");
                }
            }
        }

 

更多:

asp.net Cookie值中文乱码问题解决方法

cookie 跨域访问整理

 JQuery.cookie.js操作客户端cookie

你可能感兴趣的:(Cookie,asp.net,跨子域名域,Session丢失问题)