I have an application where we took the good old query string URL structure:
?x=1&y=2&z=3&a=4&b=5&c=6
and changed it into a path structure:
/x/1/y/2/z/3/a/4/b/5/c/6
We're using ASP.NET MVC and (naturally) ASP.NET routing.
The problem is that our parameters are dynamic, and there is (theoretically) no limit to the amount of parameters that we need to accommodate for.
This is all fine until we got hit by the following train:
HTTP Error 400.0 - Bad Request ASP.NET detected invalid characters in the URL.
IIS would throw this error when our URL got past a certain length.
Here's what we found out:
IIS does have a max path length limit, but the above error is not this.
Learn dot iis dot net How to Use Request Filtering Section "Filter Based on Request Limits"
If the path was too long for IIS, it would throw a 404.14, not a 400.0.
Besides, the IIS max path (and query) length are configurable:
<requestLimits maxAllowedContentLength="30000000" maxUrl="260" maxQueryString="25" />
After some poking around:
IIS Forums Thread: ASP.NET 2.0 maximum URL length? http://forums.iis.net/t/1105360.aspx
it turns out that this is an ASP.NET (well, .NET really) problem.
The heart of the matter is that, as far as I can tell, ASP.NET cannot handle paths longer than 260 characters.
The nail in the coffin in that this is confirmed by Phil the Haack himself:
Stack Overflow ASP.NET url MAX_PATH limit Question ID 265251
So what's the question?
The question is, how big of a limitation is this?
For my app, it's a deal killer. For most apps, it's probably a non-issue.
What about disclosure? No where where ASP.NET Routing is mentioned have I ever heard a peep about this limitation. The fact that ASP.NET MVC uses ASP.NET routing makes the impact of this even bigger.
What do you think?
By default it 2048 characters.
The default value is 4294967295 . Optional uint attribute. Specifies the maximum number of segments permitted in a URL. The default value is 32 .
Routing enables us to define a URL pattern that maps to the request handler. This request handler can be a file or class. In ASP.NET Webform application, request handler is . aspx file, and in MVC, it is the Controller class and Action method.
A route is a URL pattern that is mapped to a handler. The handler can be a physical file, such as an . aspx file in a Web Forms application. A handler can also be a class that processes the request.
I ended up using the following in the web.config to solve this problem using Mvc2 and .Net Framework 4.0
<httpRuntime maxUrlLength="1000" relaxedUrlToFileSystemMapping="true" />
To solve this, do this:
In the root web.config for your project, under the system.web node:
<system.web> <httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" /> ...
In addition, I had to add this under the system.webServer node or I got a security error for my long query strings:
<system.webServer> <security> <requestFiltering> <requestLimits maxUrl="10999" maxQueryString="2097151" /> </requestFiltering> </security> ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With