我正在尝试在ASP.NET MVC 5应用程序中上传大小为5.25 MB的mp4视频文件。
我尝试将此添加到Web.config文件中,在大多数情况下,该文件已被接受为此问题。
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" />
</system.web>
我也尝试在Web.config中设置超时
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
但是,当我上传文件时,我会收到System.Web.HttpException (0x80004005): Maximum request length exceeded.
也许有些东西需要在控制器或视图中设置?
控制器:
[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");
}
查看:
@using (Html.BeginForm("Edit", "Posts", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
如何在ASP.NET MVC 5中上传视频文件?
答案 0 :(得分:17)
尝试在web.config中添加它(以字节为单位!):
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>