iframe 跨域 cookies操作

192.168.14.69:http://192.168.14.69/payweb/iframe/default.aspx 客户端页面

通过js 动态输出iframe到localhost :default.aspx

 js Code

localhost:http://localhost/payweb/font/debitcard.aspx 被iframe嵌入页面

通过在debitcard.aspx 页面设置cookies到客户端机器 这时产生跨域操作,google搜索找到了一些解决方案,但都不成功,都是些asp 或 PHP的,基本上是添加p3p header头。没有具体提供.NET 的办法,这里从国外人的站点找到了准确的答案(难道中国没有人实际遇到吗?),添加HttpContext.Current.Response.AddHeader("p3p", "CP=\"CAO PSA OUR\"");到要读写操作cookies的页面 ,其他的就和操作一个域一样了

.net 代码


[Serializable]
public partial class front_dlp_ajax : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        
string PM = Request.Params["PM"];
        
string PP = Request.Params["PP"];
        
string result = "false";
        HttpContext.Current.Response.AddHeader(
"p3p""CP=\"CAO PSA OUR\"");
        
if (HttpContext.Current.Session[SessionKey.ORDER_ENTITY] != null)
        {            
            Order_Entity oe 
= (Order_Entity)Session[SessionKey.ORDER_ENTITY];
            
if (oe != null)
            {
                oe.Pm 
= PM;
                
string[] ppvalue = PP.ToString().Split(',');
                oe.Pg 
= ppvalue[0];
                oe.Pgc 
= ppvalue[1];

                HttpContext.Current.Session[SessionKey.ORDER_ENTITY] 
= oe;

                
#region 保存Cookies
                HttpCookie cookies 
= new HttpCookie(SessionKey.INTIMEPAY_COOKIE);
                cookies.Values[SessionKey.PM] 
= oe.Pm;
                cookies.Values[SessionKey.PGC] 
= oe.Pgc;
                cookies.Expires 
= DateTime.Now.AddDays(365);
                
//cookies.Domain = domain;
                HttpContext.Current.Response.Cookies.Add(cookies);
                
#endregion

                result 
= "true";
            }
        }
        Response.Write(result);
        Response.End();
    }
}
原文地址:https://www.cnblogs.com/jinweida/p/1361697.html