asp.net-mvc-3 - MVC3 uploadify Jquery插件报错HTTP 404和IO错误

标签 asp.net-mvc-3 jquery-plugins file-upload

我正在为 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'
    });
});

Controller 代码是

[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");
        }

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

最佳答案

您要上传多大的文件?超过 1MB 还是低于 1MB?

另外,您得到的是什么 类型的 404?如果它是 404.13(文件大小错误),那么您遇到了与我相同的问题。好消息。因为我解决了我的问题。 :)

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

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

如果您同时拥有这两个,那么问题是 IIS(我假设您正在使用)未设置为允许足够大的内容请求。

首先,将其放入您的网络配置中:

 <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 左右的任何内容。

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

关于asp.net-mvc-3 - MVC3 uploadify Jquery插件报错HTTP 404和IO错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11402356/

相关文章:

javascript - 模板内的JS

jquery - Flexslider 粘在第一帧上

c# - 如何通过Azure功能上传大文件?

javascript - 如何使用两个同名的 jQuery 插件?

asp.net-mvc-3 - 为什么这段代码不删除布局?

jquery - Json 以 unicode 形式返回我的 HTML <br/>\u003cbr/\u003e 。导致 <br/> 打印为文本而不是换行

asp.net-mvc-3 - ASP.NET MVC3 Razor - 在回发时保持滚动位置

Java:使用 Oreilly MultipartRequest servlet 发送带有附件的电子邮件

java - 如何在java中获取表单文本框和图像值表单类型enctype ="multipart/form-data"

c# - "The operation cannot be completed because the DbContext has been disposed"禁用延迟加载的异常