【问题标题】:Can I add a P3P Response Header to XMLHttpRequest?我可以向 XMLHttpRequest 添加 P3P 响应标头吗?
【发布时间】:2015-02-13 19:10:10
【问题描述】:

我在我的代码中使用了 AjaxFileUpload 插件,但 ie8 和 ie10 没有将 POST 请求标头中的 Cookie 发送到 AjaxFileUploadHandler.axd。我在 ie8 的底部看到了“眼睛”图标,并看到 AjaxFileUploadHandler.axd 被“阻塞”了,所以故意不发送 cookie。我在自己的 web.config 中有下面的标记,但问题是 AjaxFileUpload 的脚本是从 dll 中提取的,因此即使使用此 AjaxFileUploadHandler 仍然“被阻止”。我将源代码下载到了 AjaxControlToolkit,它为项目创建了 dll,现在我正试图找到可以添加 P3P 标头的位置,以便让 ie 开心。我在工具包的代码中看到了XMLHttpRequest(),有什么办法可以把这个P3P头加进去满足ie吗?

编辑:解决方法是注释掉 iframe.security = "restricted";我更新了下面的代码。

<httpProtocol>
  <customHeaders>
    <add name="P3P" value='CP="Potato"'/>
  </customHeaders>
</httpProtocol>

这个问题尤其与工具包使用的 iframe 有关。有什么方法可以将 P3P 添加到 iFrame 中?

    this.createIFrame = function() {

    var name = this._iframeName,
        iframe = document.createElement("IFRAME");

    iframe.width = "0";
    iframe.height = "0";
    iframe.style.display = "none";
    iframe.src = "about:blank";
    //iframe.src = "javascript:'<script>window.onload=function(){document.write(\\'<script>document.domain=\\\"" + document.domain + "\\\";<\\\\/script>\\');document.close();};<\/script>'";
    iframe.id = name;
    iframe.name = name;
    //iframe.security = "restricted";
    document.body.appendChild(iframe);
    iframe.contentWindow.name = name;
    $addHandlers(iframe, {
        load: Function.createDelegate(this, this.onIFrameLoadedHandler)
    });

    this._iframe = iframe;
};

this.onIFrameLoadedHandler = function (e) {
    /// <summary>
    /// Event handler to capture when iframe receive response from server.
    /// </summary>
    /// <param name="e"></param>

    if (!control._currentFileId)
        return;

    try {

        var iframe = this._iframe, doc = null;

        // Only test the iframe data, exception should thrown if something went wrong.
        if (iframe.contentDocument)
            // Firefox, Opera
            doc = iframe.contentDocument;
        else if (iframe.contentWindow)
            // Internet Explorer
            doc = iframe.contentWindow.document;
        else if (iframe.document)
            // Others?
            doc = iframe.document;

        if (doc == null)
            throw "Document not initialized";

        // finalizing and upload next file
        control.doneAndUploadNextFile(control.getCurrentFileItem());

    } catch (e) {

        // Cancelation / aborting upload can causing 'Access is denied' or 'Permission denied' on IE 9 bellow,
        // let's consider this exception is not trully error exception from server.
        if (!control._canceled || !(e.message && (e.message.indexOf("Access is denied") > -1 || e.message.indexOf("Permission denied") > -1))) {
            this.raiseUploadError(e);
            throw e;
        }
    } 
};

【问题讨论】:

    标签: javascript jquery ajax cookies ajaxcontroltoolkit


    【解决方案1】:

    解决这个问题的方法是删除一小行:

    iframe.security = "restricted";
    

    保留该行会使 iframe 具有与用户“受限”列表中的站点相同的安全级别。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 2019-11-04
      • 2011-02-24
      • 2015-02-13
      • 2016-08-29
      相关资源
      最近更新 更多