asp.net-mvc System.Web.HttpException (0x80004005): 超过最大请求长度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26442738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.Web.HttpException (0x80004005): Maximum request length exceeded
提问by Jonathan Kittell
I am trying to upload an mp4 video file that is 5.25 MB in size in an ASP.NET MVC 5 application.
我正在尝试在 ASP.NET MVC 5 应用程序中上传大小为 5.25 MB 的 mp4 视频文件。
I have tried adding this to the Web.config file which has been the accepted answer in most cases to this problem.
我已尝试将此添加到 Web.config 文件中,该文件在大多数情况下已成为此问题的公认答案。
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" />
</system.web>
I've also tried setting the timeout as well in the Web.config
我也尝试在 Web.config 中设置超时
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
However, when I go to upload the file I am getting System.Web.HttpException (0x80004005): Maximum request length exceeded.
但是,当我上传文件时,我得到了 System.Web.HttpException (0x80004005): Maximum request length exceeded.
Maybe there is something that needs to be set in the controller or view?
也许需要在控制器或视图中设置一些东西?
Controller:
控制器:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
if (fileName != null)
{
var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
View:
看法:
@using (Html.BeginForm("Edit", "Posts", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
How do you upload video files in ASP.NET MVC 5?
你如何在 ASP.NET MVC 5 中上传视频文件?
回答by Krzysztof Kalinowski
Try add this in web.config (in bytes !):
尝试在 web.config 中添加它(以字节为单位!):
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>

