ASP.NET url MAX_PATH limit
Asked Answered
L

7

11

I've found an issue with ASP.NET that I know at least has stumped one other person out there. We were trying to use an HttpModule to handle wildcard requests to a web application. The generated url is dynamic and could potentially be several hundred characters long. Unfortunately there appears to be a limitation in the aspnet_isapi.dll file that limits the length of the path in the url to MAX_PATH which is hardcoded at 260 chars.

Has anyone else ran into this and found a way around this limit? Query string parameters are not an option.

Thanks, Greg Ballard

Legerdemain answered 5/11, 2008 at 14:20 Comment(1)
The module was modifying the URL and increasing its length?Richard
G
8

This is a known issue with aspnet_isapi.dll and there is currently no workaround. The reason you don't see this issue when running your site in the built-in Visual Studio Webserver (aka Cassini) is because it's all managed code and doesn't rely on aspnet_isapi.dll.

This will get addressed in a future version of ASP.NET.

Georgiannegeorgic answered 5/11, 2008 at 17:24 Comment(2)
(+1) 4 years later, and still no fix.Laryngoscope
Still not fixed as of Dec 2012.Cental
T
8

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" />
Tidewater answered 7/4, 2011 at 18:18 Comment(1)
Thank you! I love simple fixesGroup
S
3

The problem actually lies within Windows, not ASP.NET. Windows has set MAX_PATH at 260 and when IIS takes a request for a longer filename, it will fail. You've probably found is this KBase article already, but for anyone else: http://support.microsoft.com/kb/q177665/. The Applies To: Section shows this is expected behavior from NT 3.51 all the way to Vista and Server 2003.

As for a workaround, I had a similar situation, but we would up abandoning our attempts to avoid a query string parameter and did it anyway.

Sourwood answered 5/11, 2008 at 14:42 Comment(0)
L
2

Thanks for your answer. While I didn't find that exact article, I had found similar. However, this is not a limitation in IIS. You can pass a longer path in the request to IIS and it will return the correct response. You can verify by trying with a simple html page. The problem only occurs when using aspnet_isapi.dll to handle requests. Even the integrated debug server within visual studio can handle longer paths than 260.

Legerdemain answered 5/11, 2008 at 15:22 Comment(0)
W
2

@Haacked:

Phil, you mention that this is an issue with aspnet_isapi.dll. Doesn't this mean that this issue should not exist in the IIS7 integrated pipeline mode?

From what I have heard, however, (http://forums.iis.net/t/1105360.aspx) it still does.

I am running into the same problem, and am feeling kind of hooped. It seems that ASP.NET routing is affected. So, any ASP.NET MVC application has to have URLs shorter that 260, after which it has to revert to querystrings, which seems like a complete 180!

(Sorry for answer-commenting... not enough rep to comment yet :( )

Woodhouse answered 26/7, 2009 at 9:7 Comment(0)
E
2

The registry key UrlSegmentMaxLength can be used to increase the default Windows maximum of 260 characters per Url segment in incoming HTTP requests:

  • Key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters
  • Value: UrlSegmentMaxLength
  • Type: REG_DWORD
  • Data: (Your desired new Url segment maximum allowed length, e.g. 4096)

The maximum allowed value is 32766. If a larger value is specified, it will be ignored. (Credit: Juan Mendes)

More about http.sys settings: http://support.microsoft.com/kb/820129

Restarting the PC is required to make a change to this setting take effect. (Credit: David Rettenbacher, Juan Mendes)

Original source for this answer: https://mcmap.net/q/273726/-asp-net-mvc-url-routing-maximum-path-url-length

Earth answered 10/2, 2016 at 16:11 Comment(0)
A
0

You could use an URL-rewriting ISAPI such as IIRF to rewrite the URL into something the aspnet_isapi can process.

Ambala answered 18/11, 2008 at 16:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.