System.IO.PathTooLongException On A URL

1.1k Views Asked by At

I am running into an issue that a long URL will throw a System.IO.PathTooLongException. This is somewhat strange because a System.IO.PathTooLongException is actually for physical files, it is not related to URL's.

As an example, I have a URL that looks like the following :

products-for-sale.mvc/searchterm1-something/price-1000-1500/searchterm3-etcetc/ 

Basically with the search terms bloating out the URL. We also allow a keyword search which can get kinda big if the user is looking for something specific. As a side note, the .mvc on the URL is a hangover of the application from when it ran on IIS6 and extensionless URL's were not supported, but it shouldn't really be an issue here.

What I believe the issue is, is that it looks for a physical file using the URL. I could be wrong, but I think that is the issue. Almost every article about PathTooLongException's revolve around actual files, not URL's being too long.

I had an inkling that within the IIS handler mappings, I could switch off to check if a physical file exists (I think this was a setting in IIS6?), but in IIS7 under request restrictions of a handler mapping, it only has "Invoke handler only if request is mapped to" and then file/folder/file or folder. This is NOT ticked for .mvc in IIS, and there is no where else that I have found to try and say "please don't look for a physical file if using this extension".

I could be way off base with my guesses on how to fix the issue.

1

There are 1 best solutions below

0
On

In .Net 4.0 you need to set the HttpRuntimeSection.MaxUrlLength to greater than 260.

<httpRuntime maxUrlLength="260" />

Using maxRequestPathLength worked for previous .Net versions.