在哪里设置最大查询字符串长度?

Where do I set the maximum query string length?

从带有超长查询字符串(在本例中为 2847)的 HTTP 请求中,我返回错误 404.15 并显示以下消息:

Überprüfen Sie die Einstellung "configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString" in der Datei "applicationhost.config" oder "web.config".

英文:

Check the "configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString" setting in the "applicationhost.config" or "web.config" file.

我这样做了,方法是遵循 documentation 并将最大查询字符串长度从 2048 个字符更改为 4096 个字符。

显然,上面的更改已经产生了影响,因为原来的错误信息已经消失了。

相反,我现在收到 另一个 错误,仍然 与最大查询字符串长度有关。这次,它带有 HTTP 代码 400 并表示:

Die Länge der Abfragezeichenfolge für die Anforderung überschreitet den konfigurierten maxQueryStringLength-Wert.

英文:

The query string length of the request exceeds the configured maxQueryStringLength value.

现在,我已经扫描了整个磁盘上的所有 *.config 个文件,以查找是否出现任何子字符串 maxQueryString。总共只有一个这样的事件,它是我的 IIS 默认网站的 Web.config 文件,上面写着

<requestLimits maxQueryString="4096" />

因此,一定有其他因素影响了最大查询长度 - 我还可以在哪里配置此设置?

首先,确保您在 iis 中启用了匿名身份验证:

在 web.config 文件中设置以下代码:

<system.web>

   <httpRuntime maxUrlLength="10999" maxQueryStringLength="2097151" />
                                ……
</system.web>

<system.webServer>
    <security>
    <requestFiltering>
      <requestLimits maxUrl="10999" maxQueryString="2097151" />
    </requestFiltering>
  </security>
</system.webServer>

注意:设置值比您的要求高一点。上面提到的只是一个例子。 在根文件夹配置文件中设置此值。并在进行更改后重新启动 iis。