首页 > 解决方案 > HttpException:超出最大请求长度,即使配置具有应允许的值

问题描述

我似乎不允许上传 4.3MB。我不断收到此错误:

System.Web.HttpException (0x80004005):超出最大请求长度。

我的 Web API 中的 web.config 设置:

<!-- maxRequestLength expresses POST buffer size in KB. This is the ASP.NET limit. -->
<httpRuntime targetFramework="4.5" maxRequestLength="20000" />

<!-- Let this be larger than maxRequestLength so we get ASP.NET error (if request too large) instead of IIS error. -->
<requestLimits maxAllowedContentLength="20480000" />

这是我的网络项目对 API 的调用:

var response = await httpClient.SendAsync(proxyRequest);

那总是返回上述错误。我错过了什么?我确实读过 wheremaxRequestLength需要与 相同的值maxAllowedContentLength,但这也不起作用。

标签: c#asp.netiisasp.net-web-api

解决方案


IIS 中的“默认网站”有一个配置文件,其中几乎没有任何内容。我添加maxRequestLength="20000"了它并且它起作用了。我的应用是“默认网站”下的众多应用之一。

添加了这个:

  <system.web>
    <httpRuntime targetFramework="4.5" maxRequestLength="20000" />
  </system.web>

推荐阅读