12

Here's where I'm setting maxRequestLength to 2GB (the max value), which indicates the maximum request size supported by ASP.NET:

<system.web>
    <httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>
    ...

and here I'm setting the maxAllowedContentLength to 4GB (the max value), which specifies the maximum length of content in a request supported by IIS

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="4294967295"/>
        </requestFiltering>
    </security>
    ...

I'd like to be able to upload files up to 4GB, but I'm limited by the maxRequestLength field.

I noticed that this third party upload tool (http://www.element-it.com/onlinehelp/webconfig.html) has a ignoreHttpRuntimeMaxRequestLength property, which allows it to upload files up to 4GB.

Does anyone know if I can ignore the maxRequestLength value like this other upload tool does?

Steven
  • 18,761
  • 70
  • 194
  • 296
  • What are you using to upload? It is my understanding that you can use chunked transfer-encoding to upload larger than 2GB files because the chunked transfer-encoding does not include a content-length header, so the maxRequestLength is not used. It is also my understanding most browsers do not support chunked transfer-encoding. – jac Oct 29 '12 at 21:38
  • Try use this: http://stackoverflow.com/a/12056417/551744 . I relialized splitting files with JavaScript and merging them on server side. This can help too: http://www.html5rocks.com/ru/tutorials/file/dndfiles/ – Chaki_Black Sep 09 '15 at 15:30

3 Answers3

9

Considering the Type of MaxRequestLength is a Int, at the moment there is no way to parse a value higher than Int.Max correctly.

I heard they might be increasing IIS8 but nothing concrete from Microsoft as of yet. The only way I've seen in .Net 4.5 is to use HttpRequest.GetBufferlessInputStream which

Gets a Stream object that can be used to read the incoming HTTP entity body, optionally disabling the request-length limit that is set in the MaxRequestLength property.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • 1
    Good point, I didn't realize `maxRequestLength` was `int` and not `uint`. It would kind of make more sense for it to be a `uint` since your request length can never be negative. – vane Oct 30 '12 at 15:16
  • As far as I understand Microsoft fixed ASP.NET upload limit but did not fix IIS: http://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/2642879-maximum-upload-size-in-asp-net-is-2gb-increase-it – IT Hit WebDAV Sep 23 '13 at 18:09
  • 1
    MaxRequestLength is in KB, the max value is 2 TB not GB. This is not the problem, but the fact that the normal buffered input stream as well as all as the multipart formdata parser etc. breaks down on more than 2GB. The only way around it is really GetBufferlessInputStream and parsing the request yourself. – poizan42 Mar 06 '18 at 16:01
  • @poizan42 Yes, *however* [maxAllowedContentLength](https://msdn.microsoft.com/en-us/library/ms689462(v=vs.90).aspx) is a UINT in bytes, so the max appears to be 4gb. – Erik Philips Mar 06 '18 at 18:26
  • 1
    Yes, however note that you can get rid of that by removing the RequestFilteringModule altogether from your site. After that you start hitting issues with the ASP.NET ISAPI modules failing on Content-Length headers larger than MAX_UINT because they insists on parsing it before handing off to your code. I got around it by using a rewrite rule to remove the Content-Length header (saving it in a server variable first). After that you need to read the request directly using a HttpWorkerRequest. – poizan42 Mar 06 '18 at 19:27
  • @poizan42 Good information, you may want to write your own answer here! (I would suggest it) – Erik Philips Mar 06 '18 at 20:12
  • @poizan42 Could you please let me know how you can remove Content-Length header in http request using IIS Url Rewrite module? – Ivoryguard Dec 08 '22 at 12:23
1

In my case these were the changes I needed to apply:

<system.web>
    <httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" />
</system.web>

<system.webServer>
     <serverRuntime uploadReadAheadSize="2147483647" />
     <security>
        <requestFiltering>
           <requestLimits maxAllowedContentLength="2147483647" />
        </requestFiltering>
     </security>
</system.webServer>

In order to add the serverRuntime follow the intructions in the first answer of this question

Sanchitos
  • 8,423
  • 6
  • 52
  • 52
-1

You should be able to override the settings inside machine.config by adding the same node into your application's web.config like so. Microsoft has some information about ASP.NET Configuration File Hierarchy and Inheritance.

NOTE: Erik Philips is right and the max size of maxRequestLength is 2,147,483,647 (Int32.MaxValue). This answer is to illustrate how to override a setting defined in machine.config (or any .config) from within your application's web.config/

<configuration>
    ...
    <system.web>
        <httpRuntime maxRequestLength="2147483647"/>
    ...
    ...
    </system.web>
    ...
</configuration>

In doing this though, you might also want to increase your timeout or it might, well, time out.

vane
  • 2,125
  • 1
  • 21
  • 40