我正在为 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/