Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload files over 2Gb to IIS 8 / ASP.NET 4.5?

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?

like image 504
IT Hit WebDAV Avatar asked Jan 24 '12 16:01

IT Hit WebDAV


1 Answers

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

like image 192
Taras Kozubski Avatar answered Nov 09 '22 15:11

Taras Kozubski