• 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();
        }
    }
  • 相关阅读:
    Linux环境定时备份mysql数据库
    idea以DEBUG方式启动项目卡住,但是不报错
    Linux查看防火墙,开放端口
    element动态添加删除表格的行数
    触发器编写,执行插入或update分别执行不同sql
    vue数组判断数值,遍历,过滤
    将某文件夹下的文件压缩成zip
    转载:win10专业版取消自动更新
    IIS启动应用程序池报错"服务无法在此时接受控制信息
    IIS7 设置网站默认主页(首页)
  • 原文地址:https://www.cnblogs.com/jinweida/p/1361697.html
Copyright © 2020-2023  润新知