16

I need to test a file upload component that will be accepting very large files. I want to test locally in my development environment but since I use IIS Express instead of IIS 7 I am not sure where to make the global change.

In IIS 7 the change cannot be made via the web.config but needs to be changed through the IIS Manager Tool. See this IIS article for an example.

Does anyone know how to make the same global change using IIS Express (in Visual Studio 2013)?

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
webworm
  • 10,587
  • 33
  • 120
  • 217

5 Answers5

17

If the web.config change ppascualv suggested doesn't work, try putting it in the IIS Express applicationhost.config, which can be found at

%userprofile%\my documents\iisexpress\config\applicationhost.config

under

<system.webServer>

put

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="524288000"/>
    </requestFiltering>
</security>

This should set it as a global, unless a web.config from an application overrides it.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Ezra Bailey
  • 1,434
  • 13
  • 25
  • I've been trying to figure out this for one for a whole day.. [DisableRequestSizeLimit] or any other recommendations I could find did not work, but this worked all right. Thank you! – Koray Apr 26 '21 at 09:40
6

You basically need to set both in web.config maxRequestLength and maxAllowedContentLength to upload files.

  • maxRequestLength Indicates the maximum file upload size supported by ASP.NET
  • maxAllowedContentLength This specifies the maximum length of content in a request supported by IIS.

Note:maxRequestLength is in kilobytes & maxAllowedContentLength is in Bytes

By default, Machine.config is configured to accept HTTP Requests upto 4096 KB (4 MB) and it is reflected in all your ASP.NET applications. You can change the Machine.config file directly, or you can change only the Web.config file of the application(s) you want to

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

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="1073741824" />
      </requestFiltering>
   </security>
 </system.webServer>
Heisenberg
  • 865
  • 10
  • 26
  • 4
    Your answer mentions maxRequestLength and maxAllowedContentLength but your examples show 2 instances of maxAllowedContentLength and no example of maxRequestLength – Francis Jul 23 '17 at 08:10
3

As others mentioned already you need to modify applicationhost.config and put into it

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="524288000"/>
    </requestFiltering>
</security>

What other people didn't mention is that when you are running your web app from Visual Studio, the location of applicationhost.config in the root directory of your project is
.vs\{your_project_name}\config\applicationhost.config and this is the file you will need to modify

Mykhailo Seniutovych
  • 3,527
  • 4
  • 28
  • 50
2

You can use this in web.config

<system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="524288000"/>
            </requestFiltering>
        </security>
</system.webServer>
ppascualv
  • 1,137
  • 7
  • 21
  • The instructions I read said specifically that this setting could not be made in the web.conf but had to be set via the IIS Manager app. Here is the original SO article. http://stackoverflow.com/questions/6379259/how-to-set-different-timeouts-for-different-urls-in-asp-net – webworm Feb 09 '15 at 21:20
  • 3
    This setting can be changed in web.config, did you try it? If you are moving your app between environments you are probably better off using web.config anyway over trying to do it in the GUI on each server / environment since the settings your app requires are then always copied to the environment you are deploying to? – Jamie Pollard Feb 10 '15 at 13:46
  • 1
    I think all that you can do in IIS Manager can be done in web.config, however, IIS configuration can overwrite web.config. I didn't try this specific code, by I tryed with another inside – ppascualv Feb 10 '15 at 15:23
  • The web.config change may work for IIS Express even if it doesn't for IIS 7 – Ezra Bailey Feb 10 '15 at 17:10
  • Just make sure that is only nested within tag of web.config and no other tags. – Dan Randolph Jun 21 '16 at 23:25
2

Working to get around the "400 Bad Request" due to request headers that are too big, against the Visual Studio 2019's default IIS Express instance, I couldn't get Sarah's solution to work, but found that the http.sys settings here did the trick.

Specifically, I created inside HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters a DWORD registry value called MaxRequestBytes and setting it to a large enough value. For me, 33000 was enough. Also created MaxFieldLength in the same place, and set it to 33000. A machine reboot is mandatory for the setting to become effective.

As for the cause of my problem, it's described here. It's essentially caused by authentication cookies that get placed inside the request headers. Pushing to an Azure App Service works just fine (the limit for the headers there is probably 32KB), but against the local IIS Express, it failed continuously, until the fix described above.

Mihai Albert
  • 1,288
  • 1
  • 12
  • 27