Search code examples
c#asp.net.netiis-7iis-7.5

.NET 4.6.1 and IIS7 - Cannot upload large files from WebAPI2 endpoints


I am trying to upload files using my .NET application. I cannot upload large files and it responds with 413 - Request Entity Too Large.

I tried solutions that suggested changing maxRequestLength and maxAllowedContentLength in web.config. Also changed the uploadReadAhead setting in IIS. I still am unable to upload the files.

The project has two web configs. Parent directory web config has the following settings:

<system.web>
...other lines
        <compilation targetFramework="4.6.1" />
        <httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" executionTimeout="999999" />
        <customErrors mode="Off" />
</system.web>

The web config in the inner Portal directory has:

<system.web>
...other lines
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" executionTimeout="999999" useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" />
</system.web>

<system.webServer>
...other lines
<httpRuntime targetFramework="4.6.1" requestValidationMode="2.0" executionTimeout="999999" useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" />
</system.webServer>

How do I fix this ?

Thanks.


Solution

  • Hum, that should be fine. On the other hand, seems to me that adopting some kind of nice up-loading library that up-loads in chunks would be better. This tends to "less freeze up" the user interface and also tends to not freeze up the web server either.

    I mean, for a user to up-load a big file, then they are going to be stuck watching the screen - nothing occuring. With a nice up-loader library, then only small chunks are sent up, you get a progess bar, and you have un-limited up-load file sizes.

    However, you could try in the main web.config,

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

    So, you could try adding above under system.webServer