;

How to Increase the Max Upload File Size Limit in ASP.NET or ASP.NET MVC


Tutorialsrack 20/02/2021 C# ASP.NET MVC ASP.NET

In this article, you will learn how to increase the max upload file size limit in ASP.NET or ASP.NET MVC. I think this is the most common problem which is faced by most programmers. By default, the maximum file size allowed in ASP.NET is 4MB. So in this article, you will learn how to change the default maximum upload file size in ASP.NET or ASP.NET MVC.

If you are uploading a file whose size is greater than 4096 KB, then this error occurs as given below:

Maximum request length exceeded.

If you are uploading a file whose size is too large, then you also need to set the maxAllowedContentLength size limit, otherwise, you will get an error as given below:

HTTP Error 413.1 - Request Entity Too Large

The request filtering module is configured to deny a request that exceeds the request content length.

Here is the solution to this problem:

In the Case of IIS6 or lower 

Solution 1: This can be increased by just modifying the value of the maxRequestLength attribute in the web.config as you can see in the below example. 

For example: if you want to restrict uploads to 15MB, set maxRequestLength to “15360” KB (15 x 1024).

Solution 1
<system.web>
    <!-- maxRequestLength for asp.net, in KB -->
    <httpRuntime maxRequestLength="15360"></httpRuntime>
</system.web>

In the Case of IIS7 or higher

Solution 2:  This can be increased by just modifying the value of the maxAllowedContentLength attribute inside a <system.webServer/> node to specify the size limit for requests in the web.config as you can see in the below example. The maxAllowedContentLength attribute defaults to 28.61 MB.

For example: if you want to restrict uploads to 2GB, set maxRequestLength to “2097152” KB (2 x 1024 x 1024) and set maxAllowedContentLength to2147483648” bytes (2 x 1024 x 1024 x 1024).

Solution 2
<system.web>
    <!-- maxRequestLength for asp.net, 2GB  in KB -->
    <httpRuntime maxRequestLength="2097152"></httpRuntime>
</system.web>

<system.webServer>
    <security>
        <requestFiltering>
            <!-- maxAllowedContentLength, for IIS, 2GB in bytes -->
            <requestLimits maxAllowedContentLength="2147483648"></requestLimits>
        </requestFiltering>
    </security>
</system.webServer>

I hope this article will help you to understand how to increase the max upload file size limit in ASP.NET or ASP.NET MVC.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags