在我的 c# .NET 7 项目中,我使用 JavaScript 文件 API 上传文件。 为了允许更大的文件,我更改了 IIS (v.10) 中的请求限制,如下所示:
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\SYS.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="104857600" maxUrl="12280" maxQueryString="12280" />
</requestFiltering>
</security>
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="51200" />
</system.web>
</configuration>
但是,当我上传大于 ~2 MB 的文件时,我会收到 HTTP 400 错误。
我错过了什么?
HTTP 400通常意味着大url的包请求。以这种方式设置您的配置。
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" maxUrl="30000000" maxQueryString="30000000" />
</requestFiltering>
</security>
<aspNetCore processPath="dotnet" arguments=".\SYS.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="999999999" maxQueryStringLength="2097151" maxUrlLength="2097151" />
</system.web>
</location>
</configuration>