zoukankan      html  css  js  c++  java
  • 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();
        }
    }
  • 相关阅读:
    【并发编程】并发编程随笔索引
    主题记录
    Java技术栈思维导图
    【ES 6.5.4 】ElasticSearch知识点
    Logstash Oracle同步设置
    【ES】【Reference 7.8 译】官方文档Mapping说明
    【ES】【Java High Level REST Client】官方索引和文档操作指导
    【ES】JAVA集成ES与基本操作及官方查询指导
    【实践】Effective Java实践总结
    【MyBatis】Spring集成MyBatis示例
  • 原文地址:https://www.cnblogs.com/jinweida/p/1361697.html
Copyright © 2011-2022 走看看