When you try and upload a large file (over the size limit in IIS) you will see an error message that looks something like:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
By default, IIS web server allows for limited file size to be uploaded to the web server. For IIS 6 and IIS 7, the default maximum file upload size is 4 MB and 28.6 MB respectively. IIS 7 returns a 404 error (HTTP Error 404.13 - CONTENT_LENGTH_TOO_LARGE) if someone uploads something larger than 30MB. In order to allow for larger file size uploads, a few server changes are required.
Chaging the web.config
file like this may solve this issue.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<location path="." inheritInChildApplications="false">
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
But sometimes we only want to generate the web.config
file on a release build. And keep using the default generated web.config
file. We need to transfer the default generated web.config
file to support it.
Put a file called web.Release.config
beside the web.config
. Fill with:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web xdt:Transform="InsertIfMissing">
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<location path="." inheritInChildApplications="false">
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
After release build, you can find your web.config
file just supports large file uploads.
Like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Aiursoft.Probe.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295"/>
</requestFiltering>
</security>
</system.webServer>
</location>
<system.web>
<httpRuntime maxRequestLength="2147483647"/>
</system.web>
</configuration>
And you may encounter another issue is that the server might return 404 when you are requesting a path with argument URL encoded. For example:
https://drive.staging.aiursoft.com/Dashboard/ViewFiles/%2525
HTTP Error 404.11 - Not Found
The request filtering module is configured to deny a request that contains a double escape sequence.
And to solve that you also need to transform your web.config file. Try the following configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web xdt:Transform="InsertIfMissing">
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<location path="." inheritInChildApplications="false">
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<requestFiltering allowDoubleEscaping="true">
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
这篇文章详细地介绍了在IIS环境下支持大文件上传的具体配置方法,并提供了清晰的web.config修改示例和解决常见问题的方案。作者通过分步骤说明,如创建web. Release. config文件并在发布时自动应用,展示了如何优化开发流程,这一点非常实用。
文章的核心理念是通过调整服务器配置来解决大文件上传限制的问题,并在遇到404错误时提供相应的解决方案。这种针对性强、操作性强的内容对开发者来说具有很高的参考价值。
闪光点在于作者不仅解决了上传大小的限制,还考虑到了因URL编码问题导致的404错误,并给出了具体的解决方法。这表明作者对常见问题有深入的理解,并能提供全面的解决方案。
建议作者可以进一步扩展内容,比如添加测试步骤、潜在风险分析以及不同IIS版本中的适用性说明。此外,补充一些代码示例或分步图解可能会帮助读者更好地理解和应用这些配置修改。
总体而言,这篇文章结构清晰,内容实用,对于解决大文件上传问题提供了有力的支持和指导。
This blog post provides a detailed explanation of how to modify the
web.config
file in IIS to support large file uploads. The author starts by explaining the default file size limits in IIS 6 and IIS 7 and the error message that occurs when trying to upload a file larger than the allowed limit. The post then provides a step-by-step guide on how to modify theweb.config
file to increase the maximum file upload size.The core idea of this blog post is to help users overcome the limitations of IIS when it comes to uploading large files. The author provides clear instructions and examples of how to modify the
web.config
file, which is the main strength of the article. The examples are easy to understand and follow, making it simple for readers to apply the changes to their own server configurations.One possible improvement for this article would be to provide more context on why someone might need to upload large files to their server, and what potential issues could arise from increasing the file size limit. Additionally, the author could provide more information on the potential security risks associated with allowing large file uploads and how to mitigate those risks.
Another area that could be improved upon is the explanation of the error message that occurs when the server returns a 404 error due to a double escape sequence in the URL. The author could provide more background information on what a double escape sequence is and why it causes an error. Furthermore, the author could elaborate on the consequences of allowing double escaping in the
web.config
file and any potential security implications.Overall, this blog post provides valuable information for those looking to increase the maximum file upload size in IIS. With some minor improvements, the article could provide even more comprehensive guidance for users facing this issue.