2

MVC3 C# に Uploadify v3.1 を使用しています。

私のcshtmlコードは

<div class="container_24">
    <input type="file" name="file_upload" id="file_upload" />
</div>

私のjsコードは

$(document).ready(function () {
    $('#file_upload').uploadify({
        'method': 'post',
        'swf': '../../Scripts/uploadify-v3.1/uploadify.swf',
        'uploader': 'DashBoard/UploadFile'
    });
});

そしてコントローラーコードは

[HttpPost]
        public ActionResult UploadFile(HttpPostedFileBase file)
        {
            // Verify that the user selected a file
            if (file != null && file.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/Uploads"), fileName);
                file.SaveAs(path);
            }
            // redirect back to the index action to show the form once again
            return RedirectToAction("Index", "Home");
        }

アップロード ボタンをクリックすると、2 つのエラーが表示されます。IO エラーが表示される場合もあれば、ファイルのHTTP 404エラーが表示される場合もあります。なにが問題ですか ?お願い助けて ?

4

1 に答える 1

7

アップロードするファイルのサイズは?1MB を超えるもの、またはそれ未満のものはすべてありますか?

また、どのような種類の 404 を取得していますか? 404.13 (ファイル サイズ エラー) の場合は、私と同じ問題が発生しています。朗報です。問題を解決したからです。:)

404 の種類がわからない場合 (Firebug が教えてくれます)、Windows イベント ログをチェックし、「アプリケーション」ログで次のような警告を探します。

  • イベントコード: 3004
  • イベント メッセージ: 投稿サイズが許容範囲を超えました。

これらの両方を持っている場合、問題は、IIS (使用していると思われる) が、十分な大きさのコンテンツ要求を許可するように設定されていないことです。

まず、これをWeb設定に入れます:

 <system.webServer>
    <security>
      <requestFiltering>
        <!-- maxAllowedContentLength = bytes -->
        <requestLimits maxAllowedContentLength="100000000" />
      </requestFiltering>
    </security>
  </system.webServer>

次に、「system.web」で:

<!-- maxRequestLength = kilobytes. this value should be smaller than maxAllowedContentLength for the sake of error capture -->    
<httpRuntime maxRequestLength="153600" executionTimeout="900" />

提供されているメモに注意してください - maxAllowedContentLength は BYTES 単位で maxRequestLength はKILOBYTES 単位です- 大きな違いです。

私が提供した maxAllowedContentLength 値では、約 95MB まで何でもアップロードできます。

とにかく、これはこの問題の私のバージョンを解決しました。

于 2012-08-10T20:34:24.383 に答える