ASP.net Maximum Length Exceeded

Murray Brown
Murray Brown used Ask the Experts™
on
Hi I am getting the following error is my ASP.net web app when I click a GridView button. I am using .net framework 4.6.1. What would cause this

Server Error in '/' Application.
Maximum request length exceeded.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Maximum request length exceeded.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +9935848
   System.Web.HttpRequest.FillInFormCollection() +415
   System.Web.HttpRequest.EnsureForm() +69
   System.Web.HttpRequest.get_Form() +13
   System.Web.HttpRequest.get_HasForm() +9932779
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +95
   System.Web.UI.Page.DeterminePostBackMode() +69
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +130

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3429.0
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Murray,

If you are dealing with IIS then by default, it sets up 4MB as a maximum size of the Http request (Many sites claim it is a file size but it is not, it is overall Http request size.) Now to override, you can use

<system.web>
  <httpRuntime maxRequestLength="kilobytes" />
</system.web>

Open in new window


If you are using IIS7 or above then you will also have to set
<system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="bytes" />
      </requestFiltering>
   </security>
</system.webServer>

Open in new window


Note: maxAllowedContentLength is measured in bytes while maxRequestLength is measured in kilobytes.

PS: I have not put in numbers just placeholders, based on your total upload size(the form, files etc.) you will have to put in a number there.
Example values for a 10MB upload, I suggest maxRequestLength value should be 10240 and maxAllowedContentLength value should be
12582912.

Let me know if you need more clarification/help.

Regards,
Chinmay.
Ryan ChongSoftware Team Lead
Commented:
you can make that changes in IIS console directly as well to configure Maximum request length

check the options available here

Configuring ASP.NET and IIS Request Length for POST Data
https://weblog.west-wind.com/posts/2016/apr/06/configuring-aspnet-and-iis-request-length-for-post-data
Murray BrownASP.net/VSTO Developer

Author

Commented:
Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial