Maximum request length exceeded. - asp.net

I am getting the error Maximum request length exceeded when I am trying to upload a video in my site.
How do I fix this?

If you are using IIS for hosting your application, then the default upload file size is 4MB. To increase it, please use this below section in your web.config -
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
For IIS7 and above, you also need to add the lines below:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Note:
maxRequestLength is measured in kilobytes
maxAllowedContentLength is measured in bytes
which is why the values differ in this config example. (Both are equivalent to 1 GB.)

I don't think it's been mentioned here, but to get this working, I had to supply both of these values in the web.config:
In system.web
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
And in system.webServer
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
IMPORTANT : Both of these values must match. In this case, my max upload is 1024 megabytes.
maxRequestLength has 1048576 KILOBYTES, and maxAllowedContentLength has 1073741824 BYTES.
I know it's obvious, but it's easy to overlook.

It may be worth noting that you may want to limit this change to the URL you expect to be used for the upload rather then your entire site.
<location path="Documents/Upload">
<system.web>
<!-- 50MB in kilobytes, default is 4096 or 4MB-->
<httpRuntime maxRequestLength="51200" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- 50MB in bytes, default is 30000000 or approx. 28.6102 Mb-->
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>
</system.webServer>
</location>

And just in case someone's looking for a way to handle this exception and show a meaningful explanation to the user (something like "You're uploading a file that is too big"):
//Global.asax
private void Application_Error(object sender, EventArgs e)
{
var ex = Server.GetLastError();
var httpException = ex as HttpException ?? ex.InnerException as HttpException;
if(httpException == null) return;
if (((System.Web.HttpException)httpException.InnerException).WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)
{
//handle the error
Response.Write("Too big a file, dude"); //for example
}
}
(ASP.NET 4 or later required)

The maximum request size is, by default, 4MB (4096 KB)
This is explained here.
The above article also explains how to fix this issue :)

If you can't update configuration files but control the code that handles file uploads use HttpContext.Current.Request.GetBufferlessInputStream(true).
The true value for disableMaxRequestLength parameter tells the framework to ignore configured request limits.
For detailed description visit https://msdn.microsoft.com/en-us/library/hh195568(v=vs.110).aspx

There's an element in web.config to configure the max size of the uploaded file:
<httpRuntime
maxRequestLength="1048576"
/>

To summarize all the answers in a single place:
<system.web>
<httpRuntime targetFramework="4.5.2" maxRequestLength="1048576"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Rules:
maxRequestLength (expressed in kb) value must match
maxAllowedContentLength (expressed in bytes).
most of the time your system.web section may already contains an "httpRuntime". set your targetFramework to the version of your .net used.
Notes:
default value for maxRequestLength is 4096 (4mb). max value is 2,147,483,647
default value for maxAllowedContentLength is 30,000,000 (around 30mb). max value is 4,294,967,295
more info MSDN

maxRequestLength (length in KB) Here as ex. I took 1024 (1MB) maxAllowedContentLength (length in Bytes) should be same as your maxRequestLength (1048576 bytes = 1MB).
<system.web>
<httpRuntime maxRequestLength="1024" executionTimeout="3600" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576"/>
</requestFiltering>
</security>
</system.webServer>

It bothered me for days too.
I modified the Web.config file but it didn't work.
It turned out that there are two Web.config file in my project,
and I should modified the one in the ROOT directory, not the others.
Hope this would be helpful.

If you have a request going to an application in the site, make sure you set maxRequestLength in the root web.config. The maxRequestLength in the applications's web.config appears to be ignored.

I was tripped up by the fact that our web.config file has multiple system.web sections: it worked when I added < httpRuntime maxRequestLength="1048576" /> to the system.web section that at the configuration level.

I had to edit the C:\Windows\System32\inetsrv\config\applicationHost.config file and add <requestLimits maxAllowedContentLength="1073741824" /> to the end of the...
<configuration>
<system.webServer>
<security>
<requestFiltering>
section.
As per This Microsoft Support Article

I was dealing with same error and after spending time solved it by adding below lines in web.config file
<system.web>
<httpRuntime targetFramework="4.7.1" maxRequestLength="1048576"/>
</system.web>
and
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>

I can add to config web uncompiled
<system.web>
<httpRuntime maxRequestLength="1024" executionTimeout="3600" />
<compilation debug="true"/>
</system.web>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576"/>
</requestFiltering>
</security>

Related

HttpException (0x80004005): Maximum request length exceeded

Sorry StackOverflow, I know this is already asked and found lot of answers and i tried almost all and seems alright on config but throws exception so had to bring here.
I am limiting user to upload maximum 8 photos hince look like maximum request length exceeded.
I referenced from :
Maximum value of maxRequestLength?
Maximum request length exceeded
and this is in my config file:
<location path="MyHome.aspx">
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
</system.web>
</location>
<system.webServer>
<defaultDocument>
<files>
<add value="Home.aspx" />
</files>
</defaultDocument>
</system.webServer>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
Can someone help me on this, What am i doing wrong so my file are not uploading and throwing above exception?
Thank you and Sorry for my bad English.
Your System.Web element seems to be under Location element , Make sure its under Configuration element.
Something like this :
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
</system.web>
</configuration>

Uploading digital products with size more than 5MB in nopCommerce results "Upload failed" error

I have a shop for digital products that is built with nopCommerce (a famous eccommerce software).
But uploading digital products with size more than 5MB results "Upload failed" erro, what is the solution?
First of all, check the NopCommerce setting catalogsettings.fileuploadmaximumsizebytes.
Second you can also try edit the web.config as folows
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
</requestFiltering>
</security>
</system.webServer>
By default max default file size is 4MB in ASP.Net. Look for this setting in your web.config.
<httpRuntime
maxRequestLength = "number"
/>
Change where I have the word number to your desired size in bytes.
I had to update 2 items in the web.config. Update the value to whatever you'd like your max to be.
1.Add this within the system.webServer tags:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
2.Update the httpRuntime tag:
<httpRuntime targetFramework="4.5.1" enableVersionHeader="false" maxRequestLength="2147483647"/>

how to exceed maximum iis post request Limit?

i have an asp web application, and a service witch people use to send large chunks of date trough HTTP POST.
bu Data riches many megabytes rejects the request and return nothing.
i tried to use this but didn't work. to change the limit to 10 megabytes.
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="10000000" />
</requestFiltering>
</security>
</system.webServer>
Add this to your web.config, too
<configuration>
<system.web>
<httpRuntime maxRequestLength="1000000" />
</system.web>
</configuration>
Check this link for more info: http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

asp.net file upload The connection to the server was reset while the page was loading

When I am trying to upload file of 32MB, firefox is showing following error on page.
" The connection was reset.
The connection to the server was reset while the page was loading."
I have tried foll. solutions -
1 . in <system.web>
<httpRuntime maxRequestLength="2000000000" executionTimeout="999999"/>
2 . in <system.webserver>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2000000000" />
</requestFiltering>
</security>
and
<compilation defaultLanguage="c#" debug="false" />
but still getting same error.
I think problem is related to "executionTimeout". Application is not setting this timeout for request.
Finally problem resolved...
We need to keep both tags in config file.
i.e.
<httpRuntime maxRequestLength="2000000000" executionTimeout="999999"/>
and
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2000000000" />
</requestFiltering>
</security>
Actually I was commenting one line and testing with another. :)
First: Notice that maxRequestLength is in KB whereas maxAllowedContentLength is in bytes
So you're just allowing 1MB... Increase your maxAllowedContentLength, for instance:
<requestLimits maxAllowedContentLength="2000000000" />
Second:
Try a higher execution time such as executionTimeout="999999"
I have solved the issue and set:
<httpRuntime maxRequestLength="2097151" executionTimeout="999999"/> inside tag
in the web.config file.
if maxRequestLength="2000000000" does not support then use the range 0-2097151
Hope this helps.

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

I want to upload images, it works fine on my machine but when I put my website on IIS7 server for public I can't upload anything.
Error
The request filtering module is configured to deny a request that
exceeds the request content length.
Most likely causes
Request filtering is configured on the Web server to deny the request
because the content length exceeds the configured value.
Things you can try
Verify the configuration/system.webServer/security/requestFiltering/requestLimits#maxAllowedContentLength
setting in the applicationhost.config or web.config file.
system.webServer in Web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1048576" />
</requestFiltering>
</security>
</system.webServer>
As you can see I set my maxAllowedContentLength to 1gb. Restarted my website and still getting this error. I made an /uploads/ folder on my file system where it suppose to be as well. Have no idea what causes this error and why I can't upload images.
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
From here.
For IIS7 and above, you also need to add the lines below:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
The following example Web.config file will configure IIS to deny access for HTTP requests where the length of the "Content-type" header is greater than 100 bytes.
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits>
<headerLimits>
<add header="Content-type" sizeLimit="100" />
</headerLimits>
</requestLimits>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Source: http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
I had similar issue, I resolved by changing the requestlimits maxAllowedContentLength ="40000000" section of applicationhost.config file, located in "C:\Windows\System32\inetsrv\config" directory
Look for security Section and add the sectionGroup.
<sectionGroup name="requestfiltering">
<section name="requestlimits" maxAllowedContentLength ="40000000" />
</sectionGroup>
*NOTE delete;
<section name="requestfiltering" overrideModeDefault="Deny" />

Resources