Uploading Large Files to IIS / ASP.NET
All information in this article is specific to IIS / ASP.NET. HttpListener-based server does not have any limitations listed below.
Upload Content Buffering
The file upload is performed differently in HttpListener application and in IIS/ASP.NET application. While HttpListener passes file content directly to the engine, IIS / ASP.NET first saves file content in a temporary folder limiting upload capabilities and increasing server load. To avoid upload buffering on servers side the IT Hit WebDAV Server Engine provides ResumableUploadModule that also significantly improves upload speed. To use the module in your web application add it to modules section in web.config:
In the case of IIS 7.0 integrated mode:
<configuration> <system.webServer> <modules> <addn ame="ResumableUploadModule" type="ITHit.WebDAV.Server.ResumableUpload.ResumableUploadModule, ITHit.WebDAV.Server" /> </modules> </system.webServer> </configuration>
In the case of IIS 7.0 classic mode, IIS 6.0 and 5.1:
<configuration> <system.web> <httpModules> <add name="ResumableUploadModule" type="ITHit.WebDAV.Server.ResumableUpload.ResumableUploadModule, ITHit.WebDAV.Server" /> </httpModules> </system.web> </configuration>
Note. Always use Engine.Run(HttpContext) overloaded method when utilizing this module.
Max Upload File Size
While IT Hit WebDAV server engine can process files of any size (up to 8,589,934,592 Gb) the hosting environment or you WebDAV client may not support large files upload. If you host your WebDAV server in IIS/ASP.NET you must specify the file maximum upload size in web.config of your web application. By default maximum upload size is set to 4096 KB (4 MB) by ASP.NET. To increase the upload limit add appropriate section to your web.config file and specify the limit:
In the case of IIS 7.0, both integrated and classic mode:
<configuration> <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2147483648"/> </requestFiltering> </security> </system.webServer> </configuration>
In the case of IIS 5.1, 6.0:
<configuration> <system.web> <httpRuntime maxRequestLength="2097151" /> </system.web> </configuration>
The maximum size you can set in ASP.NET is 2097151Kb = 2Gb. If you need to upload files larger than 2Gb you must implement resumable upload interfaces and upload files with segments. Note that you will need the WebDAV client application that supports resumable upload, in this case, such as based on IT Hit WebDAV Client API for .NET.
To prevent canceling script execution when uploading a large file to IIS/ASP.NET you must extend script timeout value:
HttpContext.Current.Server.ScriptTimeout = 2400; // timeout in seconds.
Note that often timeout may be caused by a database connection timeout, if you store your data in a database verify your DB connection settings.