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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011127019/article/details/89205406

一、处理代码:

    //请求结束  重写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

猜你喜欢

转载自blog.csdn.net/u011127019/article/details/89205406
今日推荐