![](/img/trans.png)
[英]ASP.NET Core 5, HttpPut request with parameters from body always returns Http 400 Bad request
[英]IIS Express Asp.Net long URL returns 400 Bad Request
更新:
堆棧跟蹤是由於沒有更改正確 Web.Config 的代理。 但是,使用 .NET Framework 4.6.1 創建新項目 -> ASP.NET Web 應用程序 (.NET Framework) 時會出現完全相同的錯誤請求錯誤。 即使在使用以下值更新Web.config
之后:
<system.web>
<authentication mode="None"/>
<httpRuntime targetFramework="4.6.1" maxUrlLength="2048" maxQueryStringLength="32768" relaxedUrlToFileSystemMapping="true" />
</system.web>
...
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxQueryString="32768" maxAllowedContentLength="32768" />
</requestFiltering>
</security>
</system.webServer>
原來的:
我有一個奇怪的問題。
以下包含 203 個字符的 URL 有效:
以下包含 303 個字符的 URL 給出了堆棧跟蹤錯誤:
此請求的 URL 長度超過了配置的 maxUrlLength 值。
異常詳細信息:System.Web.HttpException:此請求的 URL 長度超過了配置的 maxUrlLength 值。
[HttpException (0x80004005): 此請求的 URL 長度超過了配置的 maxUrlLength 值。]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9939787
System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53
這個包含 403 個字符的 URL 給了我 400 Bad Request 頁面:
問題分為兩部分:為什么我會收到不同的錯誤,我可以做些什么來修復它? 我知道我可以使用?token=
和路由[Route("testReset")]
發送請求以使其工作,但這是關於設置 URL 長度。
代碼:
[HttpGet]
[AllowAnonymous]
[Route("testReset/{token}")]
public IHttpActionResult Test(string token)
{
return Ok();
}
網頁配置:
<system.web>
<httpRuntime targetFramework="4.5.2" maxUrlLength="2048" maxQueryStringLength="32768" relaxedUrlToFileSystemMapping="true" />
</system.web>
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxQueryString="32768" />
</requestFiltering>
</security>
</system.webServer>
從這個線程:
在系統 webserver 標簽下的 Web.config 上,您必須添加以下內容:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
對我來說,同樣問題的原因是 UrlSegmentMaxLength=260 的默認值(參見https://docs.microsoft.com/en-us/troubleshoot/iis/httpsys-registry-windows )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.