Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Error 414. The request URL is too long. asp.net

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?

like image 720
Midhun Murali Avatar asked Apr 23 '14 07:04

Midhun Murali


People also ask

How do I fix HTTP Error 414 the request URL is too long?

In the case of the 414 Request-URI Too Large error, the problem is clear: the URLs being passed to the server are too big. To fix it, you'll need to change your Apache or Nginx server settings. This doesn't take too long, and once you're done, you should be back up and running.

How do you fix a URL that is too long?

How To Fix. There are several things that you can do to avoid URLs that are too long: If using dynamic URLs with URL parameters, use server-side URL rewrites to convert them into static, human-readable URLs. Try to minimize the number of parameters in the URL whenever possible.

What does HTTP Error 414 mean?

The HTTP 414 URI Too Long response status code indicates that the URI requested by the client is longer than the server is willing to interpret.


3 Answers

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 verify this, you can check the Server header value in the HTTP response headers, as per https://stackoverflow.com/a/32022511/12484.

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.

  • Reference: Http.sys registry settings for Windows

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.

like image 76
Jon Schneider Avatar answered Oct 28 '22 17:10

Jon Schneider


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.

like image 21
Zaphod Avatar answered Oct 28 '22 17:10

Zaphod


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.

like image 1
Ali Dehghan Avatar answered Oct 28 '22 15:10

Ali Dehghan