Maximum request length exceeded exception on postb

2020-07-09 06:51发布

问题:

I'm getting the following exception on a button click, for an asp page which binds more than 500 records in a gridview on page load.

My page does not have any upload control. It contains a textbox, button and the gridview. Does anyone know why this is happening.

Exception Description:

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. 

回答1:

A postback sends back the viewstate of every control - if you have a huge datagrid, then when the browser reposts that to the server, this is why you are getting the exception.

Your two options are:

  1. Set EnableViewState="false" on your GridView if you do not need the viewstate, so it's not so bloated and the postback is a reasonable size,
  2. Increase the maximum request size in web.config as shown below:

    <configuration>
        <system.web>
            <httpRuntime maxRequestLength="32768" />
        </system.web>
    </configuration>
    

Hope this helps



标签: asp.net .net