简体   繁体   English

HTTP错误414.请求URL太长。 asp.net

[英]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." 我收到错误“HTTP错误414.请求URL太长。” 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 http://www.mytecbits.com/microsoft/iis/query-string-too-long

  1. In web.config, I have maxQueryStringLength="2097151" . 在web.config中,我有maxQueryStringLength="2097151" Is this the maximum value? 这是最大值吗?
  2. In order to solve this problem, should I set maxUrl in web.config? 为了解决这个问题,我应该在web.config中设置maxUrl吗? If so, what's the maximum value supported? 如果是这样,支持的最大值是多少?

What should I do to fix this error? 我该怎么做才能解决这个错误?

This error is actually thrown from http.sys , not from IIS. 这个错误实际上是从http.sys而不是从IIS引发的。 The error gets thrown before the request is passed along to IIS in the request-handling pipeline. 在请求传递到请求处理管道中的IIS之前,会引发错误。

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, eg 65535. 为了得到https.sys接受较长的URL请求没有服务器的PC上抛出HTTP 414错误,在Windows注册表中,在计算机\\ HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\服务\\ HTTP \\参数,创建一个名称的MaxFieldLength一个DWORD类型值并且值足够大,例如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. 如果您决定进行此更改,那么显然它需要在所有环境(包括所有生产服务器)中进行 - 而不仅仅是在您的本地开发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. 此外,您的团队用于设置新服务器实例的任何脚本和/或文档都需要更新以包含此注册表设置,以便您的团队不会忘记在设置新生产的18个月后应用此设置服务器。

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. 最后,请注意,此更改可能会对服务器上运行的所有应用程序产生不利的安全后果,因为攻击者提交的大型HTTP请求不会像通常那样在管道中提前拒绝。

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. 作为使此更改绕过http.sys安全性的替代方法,请考虑将请求更改为接受HTTP POST而不是HTTP GET,并将参数放入POST请求正文而不是长URL。 For more discussion on this, see question Design RESTful GET API with a long list of query parameters . 有关此问题的更多讨论,请参阅问题设计RESTful GET API以及一长串查询参数

As described in this answer -> What is the maximum length of a URL in different browsers? 如本答案中所述 - > 不同浏览器中URL的最大长度是多少? The allowed length of a url depends on a combination of browser and server. URL的允许长度取决于浏览器和服务器的组合。 Hence it's hard to say exactly how long the url can be. 因此,很难准确地说出网址的长度。 The answer recommends to stay below 2000 char in the url. 答案建议在网址中保持低于2000字符。 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. 如果不了解有关解决方案和查询字符串的更多信息,很难给出任何建议。

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. 通常,Url有自己的长度限制,如果你设置了这个值,你可以暂时解决问题,但请记住,对于长网址情况,最佳做法是使用表单。 To be specific, it is better to use POST actions instead of Get. 具体而言,最好使用POST操作而不是Get。

just to complement, if you try with massive parameters, using Request ajax and receive de 414 ERROR. 只是为了补充,如果您尝试使用大量参数,请使用Request ajax并接收de 414 ERROR。 change the dataType property to JSON then submit as POST type. 将dataType属性更改为JSON,然后以POST类型提交。 this resolved my problem. 这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM