8

I need to upload 10Gb files to IIS in one piece. As far as I know IIS 7.x / ASP.NET 4.0 does not support uploads over 2Gb (some people say 4Gb).

Is it fixed in IIS 8 / ASP.NET 4.5?

IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98

1 Answers1

6

Here is how I upload below 4GB (I wonder how to break this limit too): App pool is .NET 4.0 Classic mode (Why there is no 4.5?). web.config:

<httpRuntime executionTimeout="2400" maxRequestLength="2099999999" />
...
<requestLimits maxAllowedContentLength="4294967290"/>

According to this article http://msdn.microsoft.com/en-us/library/hh195435%28v=vs.110%29.aspx

public override Stream InputStream
{
    get
    {
        object workerRequest = ((IServiceProvider)HttpContext.Current).GetService(typeof(HttpWorkerRequest));
        bool webDevServer = workerRequest != null &&
                            workerRequest.GetType().FullName == "Microsoft.VisualStudio.WebHost.Request";

        if (request.GetType().Assembly.GetName().Version.Major >= 4 && !webDevServer)
        {
            try // trying to set disableMaxRequestLength true for .NET 4.5
            {
                return (Stream)typeof(HttpRequest).GetMethod("GetBufferlessInputStream", BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(bool) }, null)
                                        .Invoke(request, new object[] { true });
            }
            catch (NullReferenceException)
            { // .NET 4.0 is not patched by adding method overload
                Log(DateTime.Now + ": Can not invoke .NET 4.5 method");
            }
            return (Stream) typeof (HttpRequest).GetMethod("GetBufferlessInputStream",
                                                           BindingFlags.Public | BindingFlags.Instance,
                                                           null, new Type[0], null)
                                                .Invoke(request, new object[0]);
        }
        return request.InputStream;
    }
}

Log says that method from .NET 4.5 is called without exceptions. But this link http://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/2642879-maximum-upload-size-in-asp-net-is-2gb-increase-it says: "Completed. This limit is being increased in 4.5."

So I have only one question: "HOW?"

Taras Kozubski
  • 1,854
  • 1
  • 20
  • 33
  • 3
    The 'requestLimits' element you mentioned above effectively caps IIS at 4GB. We (ASP.NET) prototyped and verified a patch that would make our 'maxRequestLength' limit a 64-bit integer instead of a 32-bit integer, but due to the hardcoded IIS cap we never checked our patch in since it wouldn't have been terribly useful anyway. The GetBufferlessInputStream overload you called out is the only way to get ASP.NET to ignore the 'maxRequestLength' limit. We're in discussions with the IIS team to try to get the hardcoded cap lifted in a future version. – Levi Sep 06 '12 at 05:01
  • 2
    @Levi There is no need to lift the cap. Just remove it. This 2Gb/4Gb limitation makes IIS/ASP.NET unusable in our projects. Our customers need to upload 10Gb files via web browser (yes, it is possible). – IT Hit WebDAV Sep 20 '12 at 02:04
  • Mb it is possible with a owin selfhosted environment? – smedasn Oct 10 '17 at 23:45
  • Has anyone made any progress on this in the last 7 years? – theycallmemorty Nov 30 '18 at 18:23