当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 二级域名或跨域共享Cookies的实现方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 二级域名或跨域共享Cookies的实现方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 338 ::
收藏到网摘: n/a

适用于Asp。 在主域名设置的Cookie,在各子域名共用;适用于博客等提供二级域名。这个问题,以网上有众多帖子,可惜都没有完整解决。
注意点:
1、当你有一个Cookie组(或叫Cookie字典)使用Domain属性指定域名之后,当你在对该组的成员进行修改或新增的时候,一定要在操作之后加上Resonse.Cookies(cookieName).Domain属性。
2、如果没有必要,请不要修改已设置Domain的Cookie组,直接使用Response.Cookies("CookieText") = CookieValue 来创建一个新的Cookie。对于每个独立的Response.Cookies("CookieText") ,不管有无字典,都一次性写入,如果需要在多次写入,换一个Response.Cookies("CookieText") 。这点很重要。
3、Response.Cookies("cookieName").Secure = False,Secure属性一定要是false
例子:
Response.Cookies("Uto")("UtorName")=UtorName
Response.Cookies("Uto")("UtorPwd")=UtorPwd
Response.Cookies("Uto").Domain="utoper.com"
Response.Cookies("Uto").Secure =False
4、IE对于.cn短域名的支持有重大BUG,没办法写入Cookies,有人测试了:http://blog.csdn.net/xssh913913/archive/2007/08/04/1725882.aspx 解决办法:
如h5.cn域名,在h5.cn所有子域名中,不管从哪个子域名接收的信息,都发往h5.cn这个域名进行写入Cookies,写入时不要设置域名,即这两句不要。
Response.Cookies("User").Domain = "h5.cn"
Response.Cookies("User").Secure =False
这样,在其他任何子域名调用Cookies时就能正常。