Monday, 7 January 2008

System.Web.HttpException: Maximum request length exceeded

The HttpRuntimeSection.MaxRequestLength is a property new to the .Net 2 framework, which is used to control the maximum request size in kilobytes for a web app. The default size is 4096 KB (4 MB), and the property is useful for preventing DOS (denial of service) attacks caused by site users posting large files to the server.

If you are uploading large files to a web app you may find the property retricting and you'll need to override the default value of this property to something you can work with. You can do this by modifying your web.config or machine.config, although I suggest setting a new value for this property in web.configs (on a per web app basis) as it would be unlikely you need all the web apps on a server to have a large upload limit and this may open up your web server to increased risk of DOS attacks.

    <httpRuntime maxRequestLength="XXXX" />

MSDN info on modifying your HttpRuntimeSection.MaxRequestLength property.