ASP.NET url MAX_PATH limit

眉间皱痕 提交于 2019-11-27 22:22:05

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.

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

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.

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.

@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 :( )

Jon Schneider

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://stackoverflow.com/a/7817739/12484

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!