MVC3 uploadify Jquery插件错误HTTP 404和IO错误

zxp*_*nce 2 file-upload jquery-plugins asp.net-mvc-3

我正在使用Uploadify v3.1 for MVC3 C#.

我的cshtml代码是

<div class="container_24">
    <input type="file" name="file_upload" id="file_upload" />
</div>
Run Code Online (Sandbox Code Playgroud)

我的js代码是

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

控制器代码是

[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");
        }
Run Code Online (Sandbox Code Playgroud)

现在,当我单击上传按钮时,它显示两个错误,有时它显示IO错误,有时它显示某些文件的HTTP 404错误.怎么了 ?请帮帮我 ?

Jon*_*han 7

您上传的文件大小是多少?一切超过1MB还是以下?

你还得到什么的404?如果它是404.13(文件大小错误)那么你遇到了同样的问题.好消息.因为我解决了我的问题.:)

如果您不确定404是什么类型(Firebug将告诉您),请检查您的Windows事件日志并查看"应用程序"日志中的警告,如下所示:

  • 活动代码:3004
  • 事件消息:帖子大小超出允许的限制.

如果你有这两个,那么问题是IIS(我假设你正在使用)没有设置为允许足够大的内容请求.

首先,将它放在您的Web配置中:

 <system.webServer>
    <security>
      <requestFiltering>
        <!-- maxAllowedContentLength = bytes -->
        <requestLimits maxAllowedContentLength="100000000" />
      </requestFiltering>
    </security>
  </system.webServer>
Run Code Online (Sandbox Code Playgroud)

然后,在"system.web"中:

<!-- maxRequestLength = kilobytes. this value should be smaller than maxAllowedContentLength for the sake of error capture -->    
<httpRuntime maxRequestLength="153600" executionTimeout="900" />
Run Code Online (Sandbox Code Playgroud)

请注意提供的注释 - maxAllowedContentLength在BYTES中,而maxRequestLength在KILOBYTES中 - 差别很大.

我提供的maxAllowedContentLength值可以让你加载任何高达95MB左右的东西.

无论如何,这解决了我的这个问题的版本.