System.Web.HttpException(0x80004005):超出最大请求长度

Jon*_*ell 14 asp.net-mvc

我试图在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>
Run Code Online (Sandbox Code Playgroud)

我也尝试在Web.config中设置超时

<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
Run Code Online (Sandbox Code Playgroud)

但是,当我上传文件时,我得到了 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");
}
Run Code Online (Sandbox Code Playgroud)

视图:

@using (Html.BeginForm("Edit", "Posts", FormMethod.Post, new { enctype =  "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="OK" />
}
Run Code Online (Sandbox Code Playgroud)

如何在ASP.NET MVC 5中上传视频文件?

Krz*_*ski 17

尝试在web.config中添加它(以字节为单位!):

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>
Run Code Online (Sandbox Code Playgroud)