2

I am working in ASP.NET MVC. I am trying to upload a file, which is successful in case of small files, but if file size is large, I get following error.

Maximum request length exceeded.

Following is my form.

@using (@Html.BeginForm("Method","Controller",FormMethod.Post,new{enctype="multipart/form-data"}))
{
   <input type="file" name="file" id="file"/>
   <input type="submit" value="Submit"/>
}

Following is controller method.

[HttpPost]
public ActionResult Method(HttpFileBase file)
{
    string path = System.IO.Path.Combine(Server.MapPath("~/Files"), file.FileName);

    file.SaveAs(path);
}

Same code works fine when file is small size i.e. of 1-2Mb, but i am trying to upload a file of 19Mb which is not being uploaded. I don't know how to specify file length and how to remove above mentioned error. Please help me.

mohsen dorparasti
  • 8,107
  • 7
  • 41
  • 61
Fakhar uz Zaman
  • 191
  • 6
  • 22
  • 4
    possible duplicate of [Maximum request length exceeded](http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded) – Erik Philips May 06 '13 at 16:33

3 Answers3

1

In your web.config under System.Web node specify

<httpRuntime maxRequestLength="NNN" />

Where NNN is file-size in Kbytes

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
1

in your web.config file under system.web add these settings :

<system.web>
  ....
   <httpRuntime maxRequestLength="XXXX" executionTimeout="XXXX" />
  ....
</system.web>

maxRequestLength is in kb and executionTimeout in minute . you should set executionTimeout to give it enough time to upload file .

check this for more details .

Community
  • 1
  • 1
mohsen dorparasti
  • 8,107
  • 7
  • 41
  • 61
1

You can change the max upload size using the web.config as suggested here, but I'd recommend binding that change to the exact URL you expect it to be uploaded to. For example, this changes the max upload size to 50MB.

<location path="Documents/Upload">
  <system.web>
    <httpRuntime maxRequestLength="51200" />
  </system.web>
</location>
Nick Albrecht
  • 16,607
  • 10
  • 66
  • 101