Web應用A中的a.htm中有一個iframe,iframe指向Web應用B的b.aspx(含Web應用B的Cookie讀寫操作,與A應用無關) B應用相當於廣告發布系統應用,b.aspx即廣告展現頁面,A應用相當於廣告發布網站,a.htm即廣告發佈頁面
A應用部署於http://www.123.com下,B應用部署於http://www.456.com.cn下
a.htm代碼如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<div>
<iframe src="http://www.456.com.cn/aditem/b.aspx" width=500 heigth=300 frameborder=1 scrolling=no></iframe>
</div>
</body>
</html>
-----------------------------------------------------------------------------
b.aspx沒有人工加任何代碼
---------------------------------------
b.aspx.cs的page_load代碼如下
for(int i=0;i<this.Request.Cookies.Count;i++){
if(this.Request.Cookies[i].HasKeys==true&&this.Request.Cookies[i].Name=="TCL"){
for(int j=0;j<this.Request.Cookies[i].Values.Count;j++){
string sname=this.Request.Cookies[i].Name;
string sitem=this.Request.Cookies[i].Values.AllKeys[j];
string svalue=this.Request.Cookies[i].Values[j];
this.Response.Cookies[sname][sitem]=svalue;
}
break;
}
}
this.Response.Cookies["TCL"]["ITEM"+DateTime.Now.ToString("yyyyMMddHHmmss")]=DateTime.Now.ToString("yyyyMMddHHmmss");
if(CADProvider.CADProvider.Domain!=null&&CADProvider.CADProvider.Domain!=""){
this.Response.Cookies["TCL"].Domain=CADProvider.CADProvider.Domain;
}
this.Response.Cookies["TCL"].Path="/aditem";
this.Response.Cookies["TCL"].Expires=DateTime.Now.AddHours(1);
-----------------------------------------------------------------------------
其中CADProvider.CADProvider.Domain為設定檔中讀取的Cookie的網域名稱
目的是開啟http://www.123.com/a.htm時,http://www.456.com.cn/aditem/b.aspx會讀寫Cookie,都是www.456.com.cn/aditem/b.aspx自己用的,和www.123.com沒有關係。
真是不明白了 CADProvider.CADProvider.Domain 配置為 www.456.com.cn / .456.com.cn / 456.com.cn / www.123.com / 123.com,Path設定和不設定 b.aspx都不能讀寫Cookie啊!
單獨調用 http://www.456.com.cn/aditem/b.aspx ,Cookie讀寫都是正常的!
------------------------------
去請教了高人,說這是跨域寫Cookie,雖然可以通過頁面跳轉的方式來寫Cookie,但我的應用程式環境不允許進行頁面跳轉方式來寫Cookie。
微軟真是的,iframe中自己寫自己的Cookie,又不訪問其他域的Cookie,這也有安全隱患?