IIS上传文件报413错误解决方案

问题说明

错误提示:(413) Request Entity Too Large
意思是上传文件过大,被服务器拒绝

解决方案

步骤1:编辑C:\Windows\System32\inetsrv\config下的applicationHost.config文件,
找到自己项目的location项,在system.webServer下添加如下代码:

<serverRuntime uploadReadAheadSize="10485760" />

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

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

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

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

步骤3:仍然是项目目录下的web.confog
按节点顺序找到 configuration > system.webServer ,添加以下代码:

<security>
  <requestFiltering>
    <!-- 10 MB in bytes -->
    <requestLimits maxAllowedContentLength="10485760" />
  </requestFiltering>
</security>

maxAllowedContentLength单位为(B:bytes),实际大小按需求设置

单位换算:1KB = 1024B,1M = 1024M

设置完成后重启应用就可以上传文件了

如果对你有用,麻烦左下角点个赞^_^

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐