1

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
MindingData
  • 11,924
  • 6
  • 49
  • 68
  • From [this question](http://stackoverflow.com/questions/530109/how-to-avoid-system-io-pathtoolongexception) the code project article appears to be the highest voted workaround: http://www.codeproject.com/Articles/22013/NET-2-0-Workaround-for-PathTooLongException – Jeremy Thompson Apr 08 '13 at 22:08
  • That would be correct if I was dealing with physical files, but in this case the URL does not map to a physical file (And should not be checked as such). – MindingData Apr 08 '13 at 22:10
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 09 '13 at 00:49

1 Answers1

0

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.

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321