Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC, Url Routing: Maximum Path (URL) Length

The Scenario

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

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.

The Nitty Gritty

Here's what we found out:

This is not an IIS problem

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"                  /> 

This is an ASP.NET Problem

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

The Question

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?

like image 890
Martin Suchanek Avatar asked Jul 26 '09 22:07

Martin Suchanek


People also ask

What is the default maximum length for URL characters in asp net?

By default it 2048 characters.

What is maximum URL segments IIS?

The default value is 4294967295 . Optional uint attribute. Specifies the maximum number of segments permitted in a URL. The default value is 32 .

What is URL Routing in MVC?

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.

What is the URL routing pattern?

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.


2 Answers

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" /> 
like image 53
lmingle Avatar answered Oct 10 '22 06:10

lmingle


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> ... 
like image 21
theJerm Avatar answered Oct 10 '22 06:10

theJerm