In this post, we want to discuss an error “maximum request length exceeded” of FileUploader control in ASP.Net. Before we get started, if you want to know about the uses of a function key, please go through the following article: The best use of Function Keys (F1 to F12).

Introduction

ASP.NET FileUpload control allows us to upload files to a Web Server or storage in a Web Form. The control is a part of ASP.NET controls and can be placed on a Web Form by simply dragging and dropping from Toolbox to a WebForm. The FileUpload control was introduced in ASP.NET 2.0.

With ASP.NET, accepting file uploads from users has become extremely easy. With the FileUpload control, it can be done with a small number of code lines, as you will see in the following example.

How to upload a file using the FileUploader control

And here is the code-behind code required to handle the upload:

Code-behind code of FileUploader control

 

Maximum request length exceeded Problem

Uploading files via the FileUpload control gets tricky with big files. The default maximum file size is 4MB – this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they’ll get an error message: “Maximum request length exceeded.”

Efficient solution for the problem
The 4MB default is set in the machine.config, but you can override it in your web.config. For instance, to expand the upload limit to 20MB, add below code to web.config:
IIS7 (and later version) has a built-in request scanning which imposes an upload file cap that defaults to 30MB. To increase it, you also need to add the lines below:
Note: maxAllowedContentLength is measured in bytes while maxRequestLength is measured in kilobytes.

Leave a Comment