【问题标题】:MVC3 uploadify Jquery plugin error HTTP 404 and IO errorMVC3 uploadify Jquery 插件错误 HTTP 404 和 IO 错误
【发布时间】:2012-07-09 20:12:00
【问题描述】:

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

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

【问题讨论】:

  • 使用 Asp.net MVC 助手生成路径:'swf': '@(Url.Content("~/Scripts/uploadify-v3.1/uploadify.swf"))', 'uploader': '@(Url.Action("DashBoard", "UploadFile"))'。您还可以设置onUploadError 以了解有关错误原因的更多信息。
  • 感谢您的评论,但您的想法不起作用:(我现在应该做什么?

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


【解决方案1】:

您要上传什么大小的文件?大于 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 左右的任何内容。

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

【讨论】:

  • 我遇到了与 OP 描述的相同的问题,此解决方案无法解决我的问题,还有其他方法可以解决问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-21
  • 2011-05-01
  • 2011-09-02
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
  • 1970-01-01
相关资源
最近更新 更多