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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 那时花开

VS2012 快捷键 VS Resharper 设置 TFS2012 独占签出实现 WinForm 生产环境、测试环境 多配置-App.config(分享) TFS2010 服务器名称变更bug 怎样和客户一起搞定需求 MSMQ XP 0x433 430 错误处理 页面关闭时弹出广告 ajax 同步异步模式问题 asp.net membership 配置错误 Test Concurrent 本地安全策略 脚本 在asp.net 3.5中sql 2005数据库缓存依赖 jQuery插入,复制、替换和删除节点 jquery 常用方法整理 存储过程生成代码 sql2000版 It 人大多路线图 收集常用数据库设计技巧 PowerDesigner 常用设置 mssql 数据库文档生成
关于 p3p ie 跨域 问题
那时花开 · 2010-03-11 · via 博客园 - 那时花开

1.二级域名

HTML code
<%@ Page Language="C#"%>
<%
HttpCookie hc = new HttpCookie("OutByTopDomain", "OutByTopDomain" + DateTime.Now.ToString());
hc.Expires = DateTime.Now.AddDays(30);//过期时间为30天
hc.Domain = "你的顶级域名";//设置共享域,如aa.com,bb.aa.com等,可以设置为aa.com,这样可以在子域共享
Response.Cookies.Add(hc);
%>
subdomain.aspx,子域读cookie

HTML code
<%@ Page Language="C#"%>
<%
Response.Write("顶级域名产生的Cookie==|" + Response.Cookies["OutByTopDomain"].Value + "|===");
%>

2.sso方案


 通过设置p3p头来实现跨域访问cookie

今天在w3网站上看到了一篇介绍p3p的文章(http://www.w3.org/TR/P3P/),利用这个可以实现跨域访问cookie,我也试验一下。 其实很简单:试验用了2个域名readlog.cn和diaor.com 首先在readlog.cn下放置一个文件setcookie.php 内容:  PHP代码 header(’P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND

 PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"’);//p3p   setcookie("TestCookie","test",time()+3600,"/",".readlog.cn");//设置cookie  再放置一个readcookie.php 内容: 然后在diaor.com下放置setcookie.php ,内容: JavaScript代码 1. <script src="http://www.readlog.cn/setcookie.php"></script>  然后访问http://www.diaor.com/setcookie.php 抓取数据包可以发现,在readlog.cn域下生成了一个cookie ,名称是TestCookie,值是test 下面访问http://www.readlog.cn/readcookie.php 来验证一下,可以发现,cookie确实设置成功了。 有兴趣可以去掉header(’P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IN

D PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"’);这句,试一下就会发现cookie能设置,但是在readlog.cn读不到这个cookie。

------IIS 通用设置

打开IIS

管理工具——〉选择一个网站——〉属性——〉http头,增加一个http头

然后输入头名:P3P

输入头内容:CP=CAO PSA OUR

------HttpModual实现

可以用httpmodual来实现在全部页面或者部分页面头部插入所需要的标志

------老外的解决方案

http://articles.sitepoint.com/article/p3p-cookies-ie6/2

-----P3P设置验证

http://www.w3.org/P3P/validator.html

利用js解决ajax跨域问题

由于安全性问题, ajax在进行请求数据时,不能跨域请求. 比如 在 http://www.a.com/ 下的页面, 无法ajax请求www.b.com/ajax.php的内容. 尽管这样的需求不多,但遇到了怎么办? 这里给出一个JS模拟ajax的方式实现跨域, 但仅仅局限于GET!

在 <script> 标签中, src的属性是可以设置非本域下的地址的. 借助此特点,即可模拟ajax的方式实现跨域. 假设 http://www.a.com/ 域名下的程序 需要通过ajax方式提交数据到 http://www.b.com/ 下的login.php?username=*&passwod=*实现登陆判断. 实现方式如下: 在http://www.a.com/内动态创建JS的方式来加载http://www.b.com/的内容,代码如下

JavaScript代码
//此代码在http://www.a.com/下   
var head = document.getElementsByTagName("head")[0];       
var js = document.createElement("script");       
js.src = "http://www.b.com/login.php?username=*&passwod=*";       
js.onload = js.onreadystatechange = function()       
{       
    if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")       
    {   
         head.removeChild(js);   
         //JS加载完毕了. 类似于ajax请求完成.   
         //执行是否登陆成功的判断   
    }       
}       
head.appendChild(js);  
这只是一个简单的例子,需要b.com下的login.php做好配合,login.php通过GET取得传入值,并生成JS的登陆标记. JS加载完成后,根据JS标记判断登陆的状态,提示登陆成功或失败.即可完成要求,代码兼容常见浏览器. :)

当然缺陷也很明显,只能支持GET的方式提交数据. 下一次我会在说说ajax跨域POST的方法.

                                           用JS或jQuery访问页面内的iframe,兼容IE/FF

js或者jQuery访问页面中的框架也就是iframe. 注意:框架内的页面是不能跨域的! 假设有两个页面,在相同域下. index.html 文件内含有一个iframe:

XML/HTML代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
<title>页面首页</title>  
</head>  
  
<body>  
<iframe src="iframe.html" id="koyoz" height="0" width="0"></iframe>  
</body>  
</html>  
iframe.html 内容:

XML/HTML代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
<title>iframe.html</title>  
</head>  
  
<body>  
<div id="test">www.koyoz.com</div>  
</body>  
</html>  
1. 在index.html执行JS直接访问:

JavaScript代码
document.getElementById('koyoz').contentWindow.document.getElementById('test').style.color='red'  
通过在index.html访问ID名为'koyoz'的iframe页面,并取得此iframe页面内的ID为'test'的对象,并将其颜色设置为红色.

此代码已经测试通过,能支持IE/firefox . 2. 在index.html里面借助jQuery访问:

JavaScript代码
$("#koyoz").contents().find("#test").css('color','red');