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

  • 相关阅读:
    最大比例(压轴题 )
    HDU-1016-素数环
    HDU-1241-油藏
    POJ-2251-地下城
    UVa-12096-集合栈计算机
    UVa-156-反片语
    UVa-10815-安迪的第一个字典
    UVa-101-木块问题
    UVa-10474-大理石在哪
    HDU-2955-Robberies
  • 原文地址:https://www.cnblogs.com/spnt/p/2595030.html
Copyright © 2011-2022 走看看