Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Web.HttpException (0x80004005): Maximum request length exceeded

Tags:

asp.net-mvc

I am trying to upload an mp4 video file that is 5.25 MB in size in an ASP.NET MVC 5 application.

I have tried adding this to the Web.config file which has been the accepted answer in most cases to this problem.

<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

<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />

However, when I go to upload the file I am getting 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?

like image 672
Jonathan Kittell Avatar asked Oct 18 '14 17:10

Jonathan Kittell


People also ask

What is Maximum request length exceeded?

Large file uploads in ASP.NET The default maximum filesize is 4MB - this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they'll get an error message: "Maximum request length exceeded."

What is maxRequestLength?

The MaxRequestLength property specifies the limit for the buffering threshold of the input stream. For example, this limit can be used to prevent denial of service attacks that are caused by users who post large files to the server.


1 Answers

Try add this in web.config (in bytes !):

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>
like image 197
Krzysztof Kalinowski Avatar answered Sep 27 '22 19:09

Krzysztof Kalinowski