8

I'm getting the error "HTTP Error 414. The request URL is too long." From the following article, I understand that this is due to a very long query string:

http://www.mytecbits.com/microsoft/iis/query-string-too-long

  1. In web.config, I have maxQueryStringLength="2097151". Is this the maximum value?
  2. In order to solve this problem, should I set maxUrl in web.config? If so, what's the maximum value supported?

What should I do to fix this error?

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
Midhun Murali
  • 2,089
  • 6
  • 28
  • 49
  • Would it be possible to replace some of the long strings in the url with integers or Guids? If there are any long string variables in the url that come from a finite list then some sort of mapping like this may allow you to shorten the url? – Adam Knights Apr 23 '14 at 08:09

4 Answers4

9

This error is actually thrown from http.sys, not from IIS. The error gets thrown before the request is passed along to IIS in the request-handling pipeline.

To get https.sys to accept longer request URLs without throwing the HTTP 414 error, in the Windows Registry on the server PC, at Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters, create a DWORD-type value with name MaxFieldLength and value sufficiently large, e.g. 65535.

If you decide to make this change, then obviously it’ll need to be made in all environments (including all production server(s)) -- not just on your local dev PC.

Also, whatever script and/or documentation your team uses to set up new server instances will need to be updated to include this registry setting, so that your team doesn’t forget to apply this setting 18 months from now when setting up a new production server.

Finally, be aware making this change could have adverse security consequences for all applications running on your server, as a large HTTP request submitted by an attacker won’t be rejected early in the pipeline as it would normally.

As an alternative to making this change to bypass the http.sys security, consider changing the request to accept HTTP POST instead of HTTP GET, and put the parameters into the POST request body instead of into a long URL. For more discussion on this, see question Design RESTful GET API with a long list of query parameters.

Community
  • 1
  • 1
Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
3

As described in this answer -> What is the maximum length of a URL in different browsers? The allowed length of a url depends on a combination of browser and server. Hence it's hard to say exactly how long the url can be. The answer recommends to stay below 2000 char in the url. I do not know why your querystring is so long. Can you shorten it? It's hard to give you any recommendations without knowing more about the solution and your query string.

Community
  • 1
  • 1
Zaphod
  • 1,412
  • 2
  • 13
  • 27
1

Generally, Url has its own limits in length and if you set this value you may solve the problem for a while, but bear in mind that for a long url situations, best practice is working with forms. To be specific, it is better to use POST actions instead of Get.

Ali Dehghan
  • 462
  • 3
  • 6
  • But only GET request can be bookmarked . After setting the above value also in web.config also the problem is not solved. – Midhun Murali Apr 23 '14 at 07:29
  • 1
    On way you can do this is URL-Shortening, the same way which is done in giant applications such as twitter, google and so on. To do that, you should consider a database table and store all detail parameters and reflect just the id (primary key) of the row to the user to bookmark. Furthermore, you should design a page to handle and parse the captured id (from request.QueryString)... hope this solution resolve your problem – Ali Dehghan Apr 23 '14 at 07:45
  • @Midhun :- Or what other thing you can do is - make one class which contains only get; and set; property. Assign your desired value to this class property and then add this class either in **ViewState** Or **Session** as per your requirement and use it in your application. So you don't need to pass massive data into query string. Hope this might help you. – Krishnraj Rana Apr 23 '14 at 09:03
1

just to complement, if you try with massive parameters, using Request ajax and receive de 414 ERROR. change the dataType property to JSON then submit as POST type. this resolved my problem.

Alisom Martins
  • 688
  • 9
  • 16