错误:IIS 8.5详细错误 - 413.1 - Request Entity Too Large

好好的网站,突然上传30多M的文件,报错:IIS 8.5详细错误-413.1-Request Entity Too Large
根据一顿搜索,找到以下解决方案:
步骤一:编辑C:/Windows/System32/inetsrv/config下的applicationHost.config文件,找到自己项目的location项,在system.webServer下添加如下代码:

<serverRuntime uploadReadAheadSize="1048576000" />

uploadReadAheadSize单位为(B:bytes),这里1048576000 = 1000M,实际大小按需求设置。完整结构如下:

<location path="EMWeb">
    <system.webServer>
        <serverRuntime uploadReadAheadSize="1048576000" />
    </system.webServer>
</location>

.

步骤二:编辑网站项目根目录下的web.config配置文件,按节点顺序找到 configuration > system.web > httpRuntime 设置 maxRequestLength 属性,单位为(B:bytes),实际大小按需求设置,注:asp.net中默认上传限制是4M(4096KB)。代码如下:

<configuration>
  <system.web>
    <httpRuntime targetFramework="4.5" requestValidationMode="2.0" maxRequestLength="1048576000" />
  </system.web>
</configuration>

步骤三:仍然是网站项目目录下的web.config配置文件,按节点顺序找到 configuration > system.webServer,添加以下代码:

<security>
  <requestFiltering>
    <!-- 1000 MB in bytes -->
    <requestLimits maxAllowedContentLength="1048576000" />
  </requestFiltering>
</security>

最后,重启IIS,重启网站就能正常上传文件了。

上面的三个步骤,并不是都要挨个做。步骤一,我发现服务器C盘下的applicationHost.config文件,里根本没有uploadReadAheadSize,于是没有管。搜索步骤二中的maxRequestLength,发现已经设置过,也没管,只新增了步骤三种的代码块,问题解决!