zoukankan      html  css  js  c++  java
  • 多个域下共享Cookie的实现


    必须设置同一个域

    写Cookie的代码

     1HttpCookie userEmailCookie = new HttpCookie("GCEmail");
     2        userEmailCookie.Value = email.ToString();
     3        //userEmailCookie.Expires = DateTime.Now.AddYears(1); //浏览器关闭,cookie自动过期
     4        userEmailCookie.Domain = domain;
     5        HttpContext.Current.Response.Cookies.Add(userEmailCookie);
     6
     7        HttpCookie userIdCookie = new HttpCookie("GCUserID");
     8        userIdCookie.Value = userId.ToString();
     9        userIdCookie.Expires = DateTime.Now.AddYears(1);
    10        userIdCookie.Domain = domain;
    11        HttpContext.Current.Response.Cookies.Add(userIdCookie);                
    12        
    13        HttpCookie lastLoginTime = new HttpCookie("LastLoginTime");
    14        lastLoginTime.Value = DateTime.Now.ToString();
    15        //lastLoginTime.Expires = DateTime.Now.AddYears(1);
    16        lastLoginTime.Domain = domain;
    17        HttpContext.Current.Response.Cookies.Add(lastLoginTime);
    18        
    19        HttpCookie userRemark = new HttpCookie("GCRemark");
    20        userRemark.Value = userRemarkInfo;
    21        //userRemark.Expires = DateTime.Now.AddYears(1);
    22        userRemark.Domain = domain;
    23        HttpContext.Current.Response.Cookies.Add(userRemark);        

    这里设置的域是有意义的,比如 你的域名为www.111.com
    你的asp程序和asp.net程序都放在上面
    那么,你那个设置域的地方都写 www.111.com 即可



  • 相关阅读:
    Quartz.net
    Perfview 分析进程性能
    windbg 分析cpu异常
    ansible-vault 教程
    ansible 自动化运维(2)
    简单生成随机测试数据
    基于 RabbitMQ-EasyNetQ 实现.NET与Go的消息调度交互
    自绘 TreeDataView 控件
    C# 创建音频WAVE文件头信息(*.wav)
    C# GOF 23种设计模式 学习Log【更新中】
  • 原文地址:https://www.cnblogs.com/goody9807/p/575366.html
Copyright © 2011-2022 走看看