|
In our last couple articles we discussed uploading files to a web server and saving them in a database.
This is an extension to those articles. Some folks have written in complaining that when they try to let
a user upload a file that is larger than 4MB that an exception is thrown. Well, this is true - by default
file upload size is limited to 4MB. In this article I'll show you how and where to override this default behaivor
on a machine, application, site, and subdirectory using the machine.config and web.config configuration files.
|
|
The <httpRuntime> Section
|
|
The <httpRuntime> section of configuration files is used to configure the ASP.NET runtime settings. The settings can be
in a configuration file that effects a machine, application, site, and subdirectory. There are three attributes that the
<httpRuntime> section supports:
| useFullyQualifiedRedirectUrl |
executionTimeout |
maxRequestLength |
| This attribute indicates whether or not client side redirects are fully qualified or relative. The value of this
attribute should be either true or false |
This attribute indicates the maximum number of seconds a request is allowed to execute before it should be automatically
halted. |
This attribute indicates the maximum upload size in KB of a file supported by ASP.NET. |
The maxRequestLength is the attribute we are going to look at. As previously mentioned the default maximum is 4MB, but if you wish to change
the size to a smaller or larger size you will want to add the following to your configuration file(s).
|
|
Configuation File
|
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<configSections>
<system.web>
<httpRuntime
executionTimeout="90"
<!-- OLD: maxRequestLength="4096" -->
<!-- NEW: --> maxRequestLength="1000"
useFullyQualifiedRedirectUrl="false"
/>
</system.web>
</configSections>
</configuration>
|
|
This code example was taken out of my machine.config file. Notice the default is 4096 KB or 4MB (OLD) - I replaced
this with a maximum of 1000 KB or 1MB. If I made no other changes this would be the default value for every ASP.NET web page
machine wide.
You can override this machine wide behaivor by using web.config files. Whether it be in an application, site, or subdirectory
you can place a web.config with it's own <httpRuntime> section in it with a different value. For example, you can a page that is
used to upload files in the root directory of your application and one in a subdirectory named /uploads. If you put a configuration file
in the /uploads directory that has the maxRequestLength that is equal to 10000 and nothing in your root directory configuration file with regards
to the <httpRuntime> section then any uploads to the root directory will not be able to exceed 1000 KB, but in the /uploads
directory files can be as large as 10MB in size or 10000 KB.
|
|
Well, that's all you need to know. Easy yes, well documented no. That is why I wrote this.
|
|