Restrict file upload size in ASP.Net Web Application

Mohammed Imtiyaz Dec 9, 2014

As you know, the default maximum file size allowed in the framework is 4MB and this is to prevent service attacks like submitting large files, which can overwhelm the server resources. In this tutorial I am going to show you how to overcome this limitation before submitting the file to the server.

Uploading large files

You cannot upload any file that is larger than this unit. However, to change this limit, you need to make changes in web.config file of your web application. To enable large file uploads you need to change the value of the following attributes.

        <httpRuntime maxRequestLength="102400" executionTimeout="102400" />

: Specifies the limit for the input stream buffering threshold in KB and allows you to control the allowed total size of the upload. Anything bigger than that will result in the default for the framework "Page not found" error.

: Specifies the maximum number of seconds for which a request is allowed to be executed before being automatically shut down by ASP.Net – the default time is 110 seconds. If the request takes longer to be executed, an exception will be thrown.

Find out more file upload attributes