Vishwamohan

Welcome to Vishwa's blog - Technology, Spirituality and More...

HttpException: Maximum request length exceeded

I have come across this error multiple times at work. This problem occurs because the default value for the maxRequestLength parameter in the section of the Machine.config or Web.Config file is 4096 (4 megabytes). As a result, files that are larger than this value are not uploaded by default.

To resolve this problem, use one of the following methods:

  • In the Machine.config file, change the maxRequestLength attribute of the <httpRuntime> configuration section to a larger value. This change affects the whole computer.
  • In the Web.config file, override the value of maxRequestLength for the application. For example, the following entry in Web.config allows files that are less than or equal to 1 GB to be uploaded:
                         <httpRuntime maxRequestLength="1048576" />

Max value for maxRequestLength attribute is "1048576" (1 GB) for .NET Framework 1.0 or 1.1 and "2097151" (2 GB) for .NET Framework 2.0.

Note: During the upload process of large files, built-in ASP.NET loads the whole file in memory before the user can save the file to the disk. Therefore, the process may recycle because of the memoryLimit attribute of the processModel tag in the Machine.config file. More info you can find in Microsoft KB article: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626

Comments (32) -

  • Vaughan Chetwynd

    5/3/2007 9:21:42 AM | Reply

    Excellent article...... solved my upload problem immediately.
    Thank you.

  • lol

    5/10/2007 3:09:43 AM | Reply

    lol

  • Shahaji Nangare (Senior System Analyst)

    5/30/2008 7:45:56 PM | Reply

    My problem is Maximum request length exceeded. It is solved immediately. Thanks.

  • Isaac Zothanpuia

    7/6/2008 8:39:24 PM | Reply

    Thanks a lot.....

  • Thiyagu

    9/7/2008 11:33:00 PM | Reply

    Really it's very helpfull articile

  • thanks

    10/26/2008 11:30:09 PM | Reply

    Thank you!  This solved my problem immediately!

  • Mark

    11/24/2008 1:42:58 AM | Reply

    I was getting this error when attempting to display and handle a large amount of data on the page. Simply changing the maxRequestLength did not fix the problem, but rather modifying the other attributes of httpRuntime in conjunction with maxRequestLength corrected the issue.

    maxRequestLength="2097151"
    executionTimeout="12000"
    useFullyQualifiedRedirectUrl="false"
    minFreeThreads="8"
    minLocalRequestFreeThreads="4"
    appRequestQueueLimit="100"
    />

    Reference: msdn.microsoft.com/en-us/library/e1f13641.aspx

    • fahad shahzad

      3/15/2016 8:22:56 PM | Reply

      Thanks dear this config solved my problem.

  • Arseny

    3/11/2009 2:54:17 PM | Reply

    Thanks. This article is still actual.

  • saravana perumal c

    7/13/2009 8:03:54 AM | Reply

    I am using IIS7. It gives error when I added "maxRequestLength" in the web.config file. Whehter this settings still exists?

  • Vishwa

    7/13/2009 2:34:20 PM | Reply

    Please make sure that you are adding it in correct section of web.config and IIS has correct .NET Framework selected for your app.

  • Wilson

    7/28/2009 5:03:48 AM | Reply

    Thanks guys. This thread helps me to resolve the problem faced.

  • Kjoplin

    8/8/2009 11:35:11 PM | Reply

    This fixed my 'Maximum Length Exceeded' type error as well. Thanks a bunch Smile

  • wibizone

    8/12/2009 5:24:19 PM | Reply

    Thats very helpfull. Thanks a lot

  • San Diego Foreclosure

    8/12/2009 6:30:56 PM | Reply

    You made me late for work reading this. Nice blog, just bookmarked it for later reference.

  • Sue

    10/13/2009 12:38:55 AM | Reply

    Thank you for this article.  I really appreciate it.  I also appreciate the fact that you got straight to the point!  Thanks.

  • Edward

    12/11/2009 11:30:04 PM | Reply

    Thank you. You saved my day.

  • Prashanth M

    2/8/2010 10:30:25 PM | Reply

    Hello,

    You saved my day with this resolution. It solved my issue instantly after modifying the web.config file.

    Thanks a lot for this help.

  • Antonio

    4/6/2010 3:13:27 PM | Reply

    Ottimo consiglio! Grazie!

  • Georgianne Tsui

    5/12/2010 11:13:14 PM | Reply

    hi it is my first post on this web and firstly I would like to thank you for the great quality information, which I found in this and all previous posts , it really helped me a lot. I will definitely add this website on my rss reader ;) Also, I would like to ask - don't you mind if I will quate some information from your blog because I am writing articles for the Hub pages, Ezine and other articles directories (this is my part time job)? It would really help me with some of mine articles. Of course, I will mention your website title or URL (not all articles directories allows URL's , so I can't 100% promise that you will get a direct link to your blog).

  • joel abulencia

    7/15/2010 9:33:42 PM | Reply

    tenkyu po jejeje

  • jamil

    9/24/2012 9:40:14 PM | Reply

    It solved my problem..thanks

  • Saud

    10/16/2012 12:08:52 AM | Reply

    Whats the max length for .NET 4  , can Ive set 2 GB right now, could I increase it?

  • sandip

    11/16/2012 9:33:44 PM | Reply

    I m working in a money market project.The customer list is near about 6500 in a gridView..When I m editing in the rowCommand of gridView,it should to go the customer id in other page to edit their details.Problems occur when i m clicking the editButton in gridView..

    I changed the web.config's system.web

    <httpRuntime maxRequestLength="51200" enable = "true" executionTimeout="45"/>

    it works fine in my local server.but logout in web server.


    plz help..

  • Mahdi hoshmandi

    12/9/2012 11:26:26 PM | Reply

    this article is helpful thank you
    طراحی وب سایت http://atit.ir

  • saeed

    2/8/2013 8:43:51 PM | Reply

    this article is helpful thank you
    طراحی وب سایت http://pars-soft.ir

  • Amina

    4/1/2013 9:32:55 AM | Reply

    Thank you very much!

  • Neelam ANnad

    4/6/2013 7:25:01 PM | Reply

    Hello All,

    I am using IIS 7 and would like to redirect the user to some error page when the Maximum request length exceeded error occurs. I am not able to do it. had tried the below options -
    1)  Server.ClearError() and Server.Transfer in Application_error and Application_Endrequest event in global.asax file.
    2)  Server.ClearError() and Server.Transfer in the OnError event of the page
    3)  Creating the custom error in web.config as below-
    <customErrors mode="RemoteOnly" defaultRedirect="GeneralError.aspx">
                  <error statusCode="413" redirect="UploadTooLarge.aspx"/>
           </customErrors>

    4)  Handling in HTTPModule
    5)  Writing the below code in web.config—
    <system.webServer>
         <modules runAllManagedModulesForAllRequests="true"/>

          <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" subStatusCode="13" />
            <error statusCode="404" subStatusCode="13" prefixLanguageFilePath="" path="http://localhost:13113/UploadTooLarge.aspx" responseMode="Redirect" />
          </httpErrors>

        </system.webServer>

  • Neelam ANnad

    4/6/2013 7:26:36 PM | Reply

    Need your help related to redirecting/transfer to a different page or display a validation message during the file upload if the file is too big on IIS7.
    I tried the code, none of the below worked –
    1)  Server.ClearError() and Server.Transfer in Application_error and Application_Endrequest event in global.asax file.
    2)  Server.ClearError() and Server.Transfer in the OnError event of the page
    3)  Creating the custom error in web.config as below-
    <customErrors mode="RemoteOnly" defaultRedirect="GeneralError.aspx">
                  <error statusCode="413" redirect="UploadTooLarge.aspx"/>
           </customErrors>

    4)  Handling in HTTPModule
    5)  Writing the below code in web.config—
    <system.webServer>
         <modules runAllManagedModulesForAllRequests="true"/>

          <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" subStatusCode="13" />
            <error statusCode="404" subStatusCode="13" prefixLanguageFilePath="" path="http://localhost:13113/UploadTooLarge.aspx" responseMode="Redirect" />
          </httpErrors>

        </system.webServer>

    I am getting Internet Explorer can’t display the page (I can open the validation page if I directly open that  page).

    Please let me know if you know anything about the working solution.

  • Brian

    4/9/2013 1:25:33 AM | Reply

    Thanks for the solution. It worked like a charm Smile

  • Mallory Hamper

    9/24/2013 9:41:34 AM | Reply

    Simply wish to say your article is as astounding. The clarity on your put up is simply nice and i could think you're an expert on this subject. Fine with your permission allow me to take hold of your RSS feed to stay up to date with forthcoming post. Thanks 1,000,000 and please keep up the gratifying work.

  • Randal Rothchild

    9/25/2013 2:40:23 PM | Reply

    I�m amazed, I must say. Rarely do I come across a blog that�s equally educative and amusing, and let me tell you, you have hit the nail on the head. The problem is something that not enough folks are speaking intelligently about. Now i'm very happy that I found this in my search for something concerning this.

Loading