【问题标题】:System.Web.HttpException (0x80004005): Maximum request length exceededSystem.Web.HttpException (0x80004005):超出最大请求长度
【发布时间】:2014-10-18 17:46:05
【问题描述】:

我正在尝试在 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 中上传视频文件?

【问题讨论】:

  • 这可能会有所帮助。 stackoverflow.com/questions/3853767/…
  • @ta.speot.is “我可以在 google 上找到它”绝不会脱离主题。但是,作为另一个 SO 问题的副本,它可以作为副本关闭。
  • 因为 Google 链接而偏离主题??? @ta.speot.is 这如何使问题脱离主题

标签: asp.net-mvc


【解决方案1】:

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

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>

【讨论】:

    猜你喜欢
    • 2015-11-02
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    相关资源
    最近更新 更多