惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Register - Security
The Register - Security
IT之家
IT之家
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
M
MIT News - Artificial intelligence
博客园 - Franky
C
Check Point Blog
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
美团技术团队
The Cloudflare Blog
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
V
V2EX
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
G
Google Developers Blog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
罗磊的独立博客
量子位
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
D
Docker
人人都是产品经理
人人都是产品经理

博客园 - 俩醒叁醉

ASP.NET MVC 4 WebAPI. Support Areas in HttpControllerSelector SQL2000安装问题(转) sql server 2008安装需要一直重启。但重启后又没有达到效果。 为数据库中所有的用户数据表生成分页存储过程 SQL 2005 字段备注获取 __doPostBack方法解析 如何在三个月掌握三年的经验(转载&&笔记) jQuery Ajax的使用 JQuery资源网站 深入分析跨域cookie的问题 CnBlogsDotText使用实例 轻松搭建博客平台-开源ASP.NET 博客Subtext 的安装 表达式目录树(源MSDN) Web 2.0 编程思想:16条法则 Control Adapter 以下代码提供查询数据库中是否存在某个值 URL Routing MVC Controllers和Forms验证 CSharp——Lambda 表达式
Cookie跨域、虚拟目录
俩醒叁醉 · 2009-03-15 · via 博客园 - 俩醒叁醉

作者:ITPUB论坛  2008-05-06

Cookie有三个属性需要注意一下:
  1. Domain 域
  2. Path 路径
  3. Expires 过期时间

  跨域操作需要设置域属性:
  Response.Cookies("MyCookie").Domain = "cnblogs.com"; (这里指的是泛域名)
  这样在其它二级域名下就都可以访问到了, ASP 和 ASP.NET 测试通过

  虚拟目录下访问:
  我在ASP端做了下测试,.NET的没试, 如果不指定Path属性, 不同虚拟目录下Cookie无法共享
  将Response.Cookies("MyCookie").Path = "/" 就可以了

  总的写法:

Response.Cookies("MyCookie").Domain = "cnblogs.com"; Response.Cookies("MyCookie").Path = "/" Response.Cookies("MyCookie").Expires = Now + 365; Response.Cookies("MyCookie")("Test") = "test"; .NET 清除Cookie HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookiename]; if (cookie != null) { cookie.Values.Clear(); SetUserCookieExpireTime(cookiename, -1); cookie.Domain = _domain; System.Web.HttpContext.Current.Response.Cookies.Set(cookie); } public static void SetUserCookieExpireTime(string key, int days) { System.Web.HttpContext.Current.Response.Cookies[key].Domain = _domain; System.Web.HttpContext.Current.Response.Cookies[key].Path = _cookiepath; System.Web.HttpContext.Current.Response.Cookies[key].Expires = DateTime.Now.AddDays(days); } .NET 添加/更新Cookie public static void AddUserCookies(string key,string value, string cookiename, string domain) { HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies[cookiename]; if (cookie == null) { cookie = new HttpCookie(cookiename); cookie.Domain = domain; cookie.Path = _cookiepath; cookie.Values.Add(key, value); HttpContext.Current.Response.AppendCookie(cookie); } else { if (System.Web.HttpContext.Current.Request.Cookies[cookiename].Values[key] != null) { cookie.Values.Set(key, value); } else { cookie.Domain = domain; cookie.Path = _cookiepath; cookie.Values.Add(key, value); HttpContext.Current.Response.AppendCookie(cookie); } } }