14

here is my URL

http://abc.domain.com/controller/action/A74444C3A7FA858C7995CA9954CBCF1E26604634767C5575396D908E8415CF8CCC04C05F49FED0AA9D9743B69ABF232BDE9787A5222D081DA638896C0D2379A673E1747A2FFE1158F14AF098B2899D2ABEB4EA738D89369627E479796B6B2B9EA9B247CC59EF10E3A88B6A56A87F0818E2AD2A942FFA31F1C941BB7AF6FDC55FE6733353F28DFAC1827688604CBFBAB4856E6C75F810D13923F9D913F51F5B02980163E6CD63BC04610AD2C12E07360D7BC2C69F1B0CD03E

There are no invalid characters in the URL itself as everything is encrypted. Still I am getting

Bad Request - Invalid URL HTTP Error 400. The request URL is invalid.

I know the URL is awfully long and I was able to resolve that issue in my Cassini by adding this httpRuntime maxUrlLength="512"

in the web.config

However in IIS7 even after playing around with the requestfiltering maxurl and maxquerystring values I have not been able to resolve this.

This is an asp.net mvc 3 application.

Qudoos
  • 594
  • 1
  • 5
  • 12
  • Have you tried playing with [``](http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits)? I know it's a version or two back from IIS7, but may have some of the same conflicts. – Brad Christie Dec 09 '11 at 15:29
  • yes I have added this requestLimits maxUrl="512" under the system.webserver – Qudoos Dec 09 '11 at 15:30

3 Answers3

31

This one is for posterity and for tracking my own problem. It's been said in another answer however, not as explicitly.

I've had the same problem on my end. The answer is of course to transfer the long URL segment to a Query string. Easier to handle.

The problem however is that HTTP.sys is not even letting the request through because a segment of the URL is exceeding 260 or so characters. However, we still had to support it.

You can change that setting in the registry. Once you reboot, the url will work.

Registry:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters]
"UrlSegmentMaxLength"=dword:00000400

This will effectively set the segment length to 1024.

Source

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
18

Your problem is you're not using a query string, but a path. A path has a maximum length of 255.

Yuriy Faktorovich
  • 67,283
  • 14
  • 105
  • 142
  • [According to MSDN](http://msdn.microsoft.com/en-us/library/ms689462%28v=vs.90%29.aspx) the default maxUrl length (in bytes) is 4096 – Brad Christie Dec 09 '11 at 15:32
  • You might be correct, but that does not explain why it works on Cassini. On my win 7 developer machine it works with Cassini but does not work when I run the same site under IIS 7. If the limit is on the path, it should be at the operating system level. No? – Qudoos Dec 09 '11 at 15:36
  • @Brad, yes I read that and have played with really large numbers to see if it works – Qudoos Dec 09 '11 at 15:39
  • @BradChristie I believe that might actually vary from browser to browser as well. Firfox and Chrome are longer, but some versions of IE are shorter. That doesn't change that parts of the URL have other limits. The hostname for example is limited to 255. – Yuriy Faktorovich Dec 09 '11 at 15:43
  • @Qudoos It would depend on how each process the request. IIS 7 might be doing some checks first before it hands over the request to the application. – Yuriy Faktorovich Dec 09 '11 at 15:44
  • if I change my url to id=[awfullylongstring] it works. Will be investigating the url rewrite solution given by Andy below.Thanks guys. – Qudoos Dec 09 '11 at 15:50
  • @Qudoos did you use `/?id=` or just `/id=`? – Yuriy Faktorovich Dec 09 '11 at 15:57
  • I used ?id=. Actually this might just be my solution, as this is just an entry point URL. – Qudoos Dec 09 '11 at 16:18
  • @Qudoos cool, was just making sure I understood for my purposes. – Yuriy Faktorovich Dec 09 '11 at 16:20
1

The final path segment is likely to be too long.

See: http://social.msdn.microsoft.com/Forums/nl/netfxnetcom/thread/723e6bfd-cab7-417b-b487-67f1dcfa524f

Andy
  • 8,870
  • 1
  • 31
  • 39