When you want to work with the FileUpload control in ASP.NET probably the most important thing to have in mind is that you are working with files, and files can get big, sometimes really big. By default with the FIleUpload control you can upload files that are 4096 KB (4 MB) in size.

Of course, you can override this setting by changing the httpRuntime maxRequestLegth in web.config file of machine.config file (if you wan’t to override the setting on the whole computer for every application etc.). For example:

<system.web>

   <httpRuntime maxRequestLength=”2097151″ enable=”true” />

</system.web>

(remember that the size is in kilobytes, so this is sround 2GB)

Now, this is all fine. You change it, you test it locally and it all works fine. At least that’s what I did. I even hosted it on the local IIS….Untill….

I published the application to a server that had IIS7 installed on it and I started getting a 404 Error. It was very frustrating really. Then I went trough the Microsoft documentation and found out that things are different on IIS7. There’s a completely different setting called maxAllowedContentLength under requestLimits under security. Example:

<security>
<requestFiltering>
<requestLimits maxAllowedContentLength=”2097151″ />
</requestFiltering>
</security>

Turns out that requestLimits is far more than just limiting the size of the files. Here’s a link for those who want to dig a little deeper on the issue:

http://www.iis.net/ConfigReference/system.webServer/security/requestFiltering/requestLimits


Hope this helps someone,

Bojan

Advertisements

Posted by TheBojan

http://www.thebojan.ninja/ http://www.thebojan.se/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s