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?

2
  • Upload how? With an input type="file"?
    – vcsjones
    Jan 24, 2012 at 16:56
  • Using PUT verb. Using POST multipart upload with 'input type="file"' is also OK, Chrome supports upload over 2Gb. Jan 24, 2012 at 17:20

1 Answer 1

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?"

4
  • 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 6, 2012 at 5: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). Sep 20, 2012 at 2:04
  • Mb it is possible with a owin selfhosted environment?
    – smedasn
    Oct 10, 2017 at 23:45
  • Has anyone made any progress on this in the last 7 years? 🤣 Nov 30, 2018 at 18:23

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.