1

ASP.NET 環境で Kendo UI Uploader を非同期モードで使用しようとしましたが、サイトのデモと非常によく似たコードを使用して、IE8 と Chrome 30.0.1599.101 の両方で JQuery クロス サイト スクリプティング エラーのように見えます。メートル

使用されているコードは次のとおりです。

index.chtml

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="css/kendostyles/kendo.common.min.css" rel="stylesheet" />
    <link href="css/kendostyles/kendo.default.min.css" rel="stylesheet" />
    <script src="scripts/kendojs/jquery.min.js"></script>
    <script src="scripts/kendojs/kendo.all.min.js"></script>
</head>
<body>



<div style="width:45%">
    <div style="width:45%">
        <div class="demo-section">
            <input name="files" id="files" type="file" />
        </div>
    </div>

    <script>

        $(document).ready(function () {

            $("#files").kendoUpload({
                async: {
                    saveUrl: "save",
                    removeUrl: "remove",
                    autoUpload: true
                }
            });
        });
    </script>
</div>


</body>
</html>

ヒットすらしていない非常に単純なアップロードコードがありますが、完全を期すために提供します。

public ActionResult Save(IEnumerable<HttpPostedFileBase> files)
{
    // The Name of the Upload component is "files"
    if (files != null)
    {
        foreach (var file in files)
        {
            // Some browsers send file names with full path.
            // We are only interested in the file name.
            var fileName = Path.GetFileName(file.FileName);
            var physicalPath = Path.Combine(Server.MapPath("~/Uploads"), fileName);
            // The files are not actually saved in this demo
            // file.SaveAs(physicalPath);
        }
    }

    // Return an empty string to signify success
    return View();
}

アップロードするファイルを選択すると、次の JavaScript ポップアップ メッセージが表示されます。

Error! Upload failed.Unexpected server response - see console.

コンソールを表示すると、次のようになります。

Server response: Error trying to get server response: SecurityError: Blocked a frame with origin "http://localhost:21739" from accessing a frame with origin "null".  The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "data". Protocols must match.

同様の問題を探し回った後、問題を解決しようとして、global.asax ファイルを変更して問題を回避しようとしました

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
}

しかし、それは効果がありませんでした。

この種のエラーが表示されたときに非同期剣道ファイルのアップロードを機能させる方法は何ですか?同じ状況に苦しんでいる人を見つけることができませんでした?

4

1 に答える 1