2014-10-18 249 views
8

我正尝试上传一个在ASP.NET MVC 5应用程序中大小为5.25 MB的mp4视频文件。System.Web.HttpException(0x80004005):超出最大请求长度

我已经尝试将此添加到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?

+2

这可能会有帮助。 http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded – 2014-10-18 17:50:18

+0

这个问题似乎是脱离主题,因为它是一个完全重复的http://www.google.com/#q=Maximum% 20request%20length%20exceeded – 2014-10-19 07:42:04

+3

@ ta.speot.is“我可以在谷歌上找到它”绝不会让它脱离主题。然而,作为另一个SO问题的副本使其可以作为副本关闭。 – 2014-10-19 08:09:14

回答

13

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

<system.webServer> 
    <security> 
     <requestFiltering> 
     <requestLimits maxAllowedContentLength="1073741824" /> 
     </requestFiltering> 
    </security> 
</system.webServer> 
相关问题