zoukankan      html  css  js  c++  java
  • 二级域名共享Cookie

     我是不怎么喜欢写技术文章的,一方面会了感觉没啥,另一方面不会就去学习。始终感觉是没啥可写的。但是没有分享肯定是不好的,以后会把在项目中遇到的大大小小的问题的解决方案都贴出来,供大家参考和指出我的不足。废话不多了,说正事。

     以前没怎么做过跨域的请求,现在要做Cookie的跨二级域名共享,就查了查资料写出了如下方法。

            public static void WriteCookie(string strName, string key, string strValue,string domain)
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
                if (cookie == null)
                {
                    cookie = new HttpCookie(strName);
                }
                cookie.Domain = domain;
                cookie.Path = "/";
                cookie[key] = strValue;
                HttpContext.Current.Response.AppendCookie(cookie);
            }

    cookie在二级域名中跨域共享是很容易实现的。

    参数domain为网站主域名(不为任何二级域名格式):如有www.test.com,event.test.com.usercp.test.com,此时的domain参数为test.com

  • 相关阅读:
    作业6
    作业8
    作业7
    作业5
    作业4
    作业3
    作业2
    作业1
    浏览器跨域的细节
    解析node-cors模块
  • 原文地址:https://www.cnblogs.com/spnt/p/2595030.html
Copyright © 2011-2022 走看看