We help IT Professionals succeed at work.

Maximum request length exceeded

gogetsome asked
Medium Priority
Last Modified: 2008-02-20
Hello, I have a simple gridview that I want to allow editing with. Very simple really. The data populates correctly, But when you click on the edit button you get the error below. What could be causing this? I've ton of these and have never seen this error.
Exception Details: System.Web.HttpException: Maximum request length exceeded.

Stack Trace:
[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +293
   System.Web.HttpRequest.FillInFormCollection() +173
   System.Web.HttpRequest.get_Form() +64
   System.Web.HttpRequest.get_HasForm() +79
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +63
   System.Web.UI.Page.DeterminePostBackMode() +134
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +251

Here is the code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CUSTNMBR"
                        <asp:CommandField ShowEditButton="True" />
                        <asp:BoundField DataField="CUSTNMBR" HeaderText="CUSTNMBR" ReadOnly="True" SortExpression="CUSTNMBR" />
                        <asp:BoundField DataField="CUSTNAME" HeaderText="CUSTNAME" SortExpression="CUSTNAME" />
                        <asp:BoundField DataField="CUSTCLAS" HeaderText="CUSTCLAS" SortExpression="CUSTCLAS" />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>"
                    SelectCommand="SELECT [CUSTNMBR], [CUSTNAME], [CUSTCLAS] FROM [RM00101] ORDER BY [CUSTCLAS], [CUSTNAME]"
                    UpdateCommand="UPDATE [RM00101] SET [CUSTNAME] = @CUSTNAME, [CUSTCLAS] = @CUSTCLAS WHERE [CUSTNMBR] = @CUSTNMBR">
                        <asp:Parameter Name="CUSTNMBR" Type="String" />
                        <asp:Parameter Name="CUSTNAME" Type="String" />
                        <asp:Parameter Name="CUSTCLAS" Type="String" />
                        <asp:Parameter Name="CUSTNMBR" Type="String" />
                        <asp:Parameter Name="CUSTNMBR" Type="String" />
                        <asp:Parameter Name="CUSTNAME" Type="String" />
                        <asp:Parameter Name="CUSTCLAS" Type="String" />


Watch Question

Looks like it is being caused by SQL Server: check the field length in SQL Table and the field length that is posted for insertion.

I believe that the problem is in regards to how much data you are passing back up to the server when you click your edit button.   By default asp.net only allows up to 4MB of data to be passed up in a request.   Because of this, if your datagrid and all the data included with it is greater than that limit then it will throw this error.   Some pages will see this error if you have a lot of controls and use viewstate because the viewstate will be huge and will be posted back even if not using it.   Here is an article talking about the problem and how to solve it. The quickest thing to try is to update the webconfig to use a larger maxRequestLength value.   See the article for more detail on this.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

How big is your viewstate? Is that causing it? Use something like Fiddler or ieHttpHeaders to inspect the length of the request you are sending, as jjardine says, it is likely that it is over the limit ASP.NET allows, or the web server is restricted to.



jjardine thanks for the info. Adding  <httpRuntime maxRequestLength="8192" /> to the web.config as stated in the article fixed the issue.

I hope your network is fast if your pages are that big ;-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.