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 I
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.
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.NETmaxAllowedContentLength
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>
You can use this in web.config
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="524288000"/>
</requestFiltering>
</security>
</system.webServer>
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.