Introduction
One of the most common issues encountered in ASP.NET applications is the "Maximum Request Length Exceeded" error. This error occurs when a user attempts to upload a file that exceeds the maximum request size configured in the application or web server.
This article explains why the error occurs and how to configure ASP.NET and IIS to allow larger file uploads.
Understanding the Error
When a user uploads a file, ASP.NET validates the size of the incoming request before processing it.
If the uploaded file exceeds the configured limit, ASP.NET throws an exception similar to:
Maximum request length exceeded.
This typically happens when:
Uploading large documents
Uploading videos or images
Importing large datasets
Sending large multipart/form-data requests
ASP.NET Request Size Configuration
ASP.NET uses the maxRequestLength attribute in the <httpRuntime> section to control the maximum request size.
Example Configuration
<system.web>
<httpRuntime
targetFramework="4.8"
maxRequestLength="102400" />
</system.web>
Explanation
| Setting | Description |
|---|---|
| targetFramework="4.8" | Specifies the .NET Framework version |
| maxRequestLength="102400" | Maximum request size in KB |
The value is specified in kilobytes (KB).
Calculation
102400 KB = 100 MB
Therefore:
maxRequestLength="102400"
allows uploads up to approximately 100 MB.
IIS Request Size Configuration
Even if ASP.NET allows larger uploads, IIS may still block the request.
IIS uses the maxAllowedContentLength attribute under the requestFiltering section.
Example Configuration
<system.webServer>
<security>
<requestFiltering>
<requestLimits
maxAllowedContentLength="104857600" />
</requestFiltering>
</security>
</system.webServer>
Explanation
| Setting | Description |
|---|---|
| maxAllowedContentLength | Maximum request size in bytes |
Calculation
104857600 bytes = 100 MB
So this setting also allows uploads up to 100 MB.
Complete Web.config Example
To support file uploads up to 100 MB, configure both ASP.NET and IIS:
<configuration>
<system.web>
<httpRuntime
targetFramework="4.8"
maxRequestLength="102400" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits
maxAllowedContentLength="104857600" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
Why Both Settings Are Required
Many developers update only the maxRequestLength value and still receive upload errors.
This happens because:
ASP.NET Layer
maxRequestLength="102400"
Controls the request size accepted by ASP.NET.
IIS Layer
maxAllowedContentLength="104857600"
Controls the request size accepted by IIS.
The upload succeeds only when both limits are large enough.
Common Size Conversions
50 MB
maxRequestLength="51200"
maxAllowedContentLength="52428800"
100 MB
maxRequestLength="102400"
maxAllowedContentLength="104857600"
200 MB
maxRequestLength="204800"
maxAllowedContentLength="209715200"
500 MB
maxRequestLength="512000"
maxAllowedContentLength="524288000"
Additional Recommendations
1. Validate File Size Before Upload
Implement client-side validation to prevent users from uploading oversized files.
Example:
if (file.size > 100 * 1024 * 1024) {
alert("File exceeds 100 MB limit.");
}
2. Restrict File Types
Allow only required file extensions:
var allowedExtensions = new[] { ".pdf", ".docx", ".xlsx" };
3. Use Streaming for Large Files
For uploads larger than several hundred megabytes, consider streaming uploads rather than loading the entire file into memory.
4. Configure Request Timeout
Large uploads may require increasing execution timeout:
<httpRuntime
executionTimeout="3600"
maxRequestLength="102400" />
This example allows processing for up to one hour.
Troubleshooting Checklist
If the error persists:
Verify
maxRequestLengthis configured.Verify
maxAllowedContentLengthis configured.Restart IIS after changes.
Check application pool settings.
Verify available server disk space.
Check reverse proxy or load balancer limits.
Verify browser upload restrictions.
Conclusion
The "Maximum Request Length Exceeded" error occurs when an uploaded file exceeds the size limits configured in ASP.NET or IIS. To resolve the issue, increase both the maxRequestLength value in the <httpRuntime> section and the maxAllowedContentLength value in the IIS <requestFiltering> section.
For a 100 MB upload limit, use:
<httpRuntime targetFramework="4.8" maxRequestLength="102400" />
<requestLimits maxAllowedContentLength="104857600" />
By configuring both settings correctly, your ASP.NET application can successfully handle larger file uploads without triggering request size exceptions.
Summary
The "Maximum Request Length Exceeded" error occurs when uploaded files exceed the request size limits configured in ASP.NET or IIS. To support larger uploads, configure both maxRequestLength in the ASP.NET <httpRuntime> section and maxAllowedContentLength in the IIS <requestFiltering> section. Ensuring that both settings are aligned, along with proper validation, timeout configuration, and troubleshooting checks, helps prevent upload failures and enables reliable handling of large files.

Join the conversation! Your thoughts help the community grow.