Update:
The stack trace was due to a proxy where the correct Web.Config was not altered. However creating a new project -> ASP.NET Web Application (.NET Framework) using .NET Framework 4.6.1 the exact same bad request error is present. Even after updating Web.config with the following values:
<system.web>
<authentication mode="None"/>
<httpRuntime targetFramework="4.6.1" maxUrlLength="2048" maxQueryStringLength="32768" relaxedUrlToFileSystemMapping="true" />
</system.web>
...
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxQueryString="32768" maxAllowedContentLength="32768" />
</requestFiltering>
</security>
</system.webServer>
Original:
I'm having a weird problem.
The following URL with 203 characters works:
https://localhost:44369/api/Account/testReset/AQAAANCMnd8BFdERjHoAwE12fCl12bsBAAAA9B6VBWG0rESm48zX3kvFAgAAAAACAAAAAAAQZgAAAAEAACAAAABrejIuYGBxLG912bGeknd3Iww12b9dhdzE99tfhdGW1FPbmQAAAAAOgAAAAAIAACAAAAAWg
The following URL with 303 characters gives a stack trace error:
https://localhost:44369/api/Account/testReset/AQAAANCMnd8BFdERjHoAwE12fCl12bsBAAAA9B6VBWG0rESm48zX3kvFAgAAAAACAAAAAAAQZgAAAAEAACAAAABrejIuYGBxLG912bGeknd3Iww12b9dhdzE99tfhdGW1FPbmQAAAAAOgAAAAAIAACAAAAAWgI6mOVdROCbpPBF71QQsivA1VaIPJuALkCN4A5kFUEAAAAAa905JtNQkjp1KFUZJks6PuShgpYDv4nQvTAJTYnzxJu5BvT3AdB12b
The length of the URL for this request exceeds the configured
maxUrlLength value.
Exception Details: System.Web.HttpException: The length of the URL
for this request exceeds the configured maxUrlLength value.
[HttpException (0x80004005): The length of the URL for this request
exceeds the configured maxUrlLength value.]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9939787
System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53
This URL with 403 characters gives me 400 Bad Request page:
https://localhost:44369/api/Account/testReset/AQAAANCMnd8BFdERjHoAwE12fCl12bsBAAAA9B6VBWG0rESm48zX3kvFAgAAAAACAAAAAAAQZgAAAAEAACAAAABrejIuYGBxLG912bGeknd3Iww12b9dhdzE99tfhdGW1FPbmQAAAAAOgAAAAAIAACAAAAAWgI6mOVdROCbpPBF71QQsivA1VaIPJuALkCN4A5kFUEAAAAAa905JtNQkjp1KFUZJks6PuShgpYDv4nQvTAJTYnzxJu5BvT3AdB12bIobF0DrIjWDgzrTa7ddaOLWfekVuEvEZJQAAAAN9tYCLKXD6Z1BembCCgBa7XkUhs0aOsLj0euwKYaR12b799hD812bO1pMsKXwl
The question is two parts: Why do I receive different errors and what can I do to fix it? I know I can send the request with ?token= with route [Route("testReset")] to get it to work but this is about setting the URL length.
Code:
[HttpGet]
[AllowAnonymous]
[Route("testReset/{token}")]
public IHttpActionResult Test(string token)
{
return Ok();
}
Web.config:
<system.web>
<httpRuntime targetFramework="4.5.2" maxUrlLength="2048" maxQueryStringLength="32768" relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxQueryString="32768" />
</requestFiltering>
</security>
</system.webServer>
From this thread:
How do I increase the maxUrlLength property in the config in asp.net MVC 3?
On Web.config under system webserver tag u have to add this :
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
For me the reason of the same problem was default value of UrlSegmentMaxLength=260
(see https://learn.microsoft.com/en-us/troubleshoot/iis/httpsys-registry-windows)
I am generating an XML using JavaScript and trying to send it to an action method through AJAX POST call. It's working fine up to certain XML length. But as the XML is getting lengthier, I am receiving broken XML in the action method.
I tried followings to increase the request length but still unable to fix the issue. However AJAX GET is working fine.
Please do help me on this.
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="3000000000" />
</requestFiltering>
</security>
</system.webServer>
you have increased maxJsonLength but that is for GET only, try to increase the value of maxRequestLength also..
I'm having the seuinte error when trying to debug my application.
HTTP Error 404.13 - Not Found
The request filtering module is configured to deny a request that
exceeds the request content size .
Check configuration/system.webServer/security/requestFiltering/requestLimits#maxAllowedContentLength setting in applicationhost.config or web.config file.
My web.config
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="31457280"/>
</requestFiltering>
</security> </system.webServer>
More Information:
This and a security feature . NOT Change a Less Than the scope of the change is fully understood. Fast You CAN configure IIS server to reject requests Whose content is greater than hum value specified . If the request content to Greater Than the set * Size ESSE error is returned. Required to Increase * Content size , modify the configuration configuration/system.webServer/security/requestFiltering/requestLimits#maxAllowedContentLength .
You'll need to adjust the maximumRequestLength property within your application to handle such large files.
It's important to know that maxAllowedContentLength is measured in bytes and maximumRequestLength is measured in kilobytes when settings these values so you'll need to adjust them accordingly:
<configuration>
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" timeout="3600" />
</system.web>
</configuration>
<!-- IIS Specific Targeting (noted by the system.webServer section) -->
<system.webServer>
<security>
<requestFiltering>
<!-- This will handle requests up to 1024MB (1GB) -->
<requestLimits maxAllowedContentLength="1048576000" />
</requestFiltering>
</security>
</system.webServer>
Do you have
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
in your configuration also? I think you need to also add <httpRuntime maxRequestLength="1048576" /> to yoru config file.
I got this from here - Maximum request length exceeded
So I recently wrote a simple service to upload files to my server. Everything works fine. My web.config looks like this (max upload size is restricted to 20 MB):
<configuration>
<system.web>
<httpRuntime maxRequestLength="20480" executionTimeout="600" />
<httpHandlers>
<add path="api*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
...
</system.web>
</configuration>
All my routes begin with /api/, for example my upload service is at /api/documents/upload.
Now my question is: Is it possible to define different upload sizes for different services? (in my example every service is limited to 20 MB!)
I tried some stuff with the location-tag but it didn't worked with the httpRuntime-tag. Anyone tried something like this already?
Use the location element, it should work (Check the path without ~/)
<configuration>
<location path="api/documents/upload">
<system.web>
<httpRuntime maxRequestLength="20480" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="20971520" />
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
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>