Click here to Skip to main content
15,883,809 members
Articles / Web Development / ASP.NET
Article

Setting up Web.config to allow uploading of large files by ASP .NET applications

Rate me:
Please Sign up or sign in to vote.
4.24/5 (42 votes)
29 Jun 2005Apache1 min read 302.1K   2.9K   59   18
This article shows how to setup Web.config to allow uploading of files larger than 4 MB by ASP.NET applications.

Image 1

Introduction

During the construction of an intranet application that allows users to upload documents and share information between users, I noticed that when a user tries to upload files that are larger than 4 MB, he is asked for the user/password and even if he enters the correct user/password, the file is not uploaded, and he gets a HTTP 401.1 error.

Of course, this should not be an article, but CodeProject doesn't have a "quick tip section"-like, so here it goes.

The problem

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.

The solution

Open your Web.config file, and just below the <system.web> tag, add the following tag:

XML
<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096" 
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4" 
appRequestQueueLimit="100" 
enableVersionHeader="true"
/>

Now, just take a look at the maxRequestLength="4096" attribute of the <httpRuntime> tag. As you may have realized, all you need to do is change the value to some other value of your choice (8192 for 8 Mb, 16384 for 16 Mb, 65536 for 64 Mb, and so on...).

That's it. I hope it is useful to you.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Chief Technology Officer Stablehouse
Bermuda Bermuda
C. Augusto Proiete has been programming for over 20 years, having first started with Clipper Summer'87.

He loves software development and reverse engineering. Today his main development technologies includes Blazor, ASP .NET Core, C#, SQL Server. He also has the following titles:

MVP - Microsoft Most Valuable Professional;
MCT - Microsoft Certified Trainer;
MCPD - Microsoft Certified Professional Developer;
MCTS - Microsoft Certified Technology Specialist;
MCSD - Microsoft Certified Solution Developer;
MCDBA - Microsoft Certified Database Administrator.

Technical blog:
https://augustoproiete.net

Comments and Discussions

 
QuestionThe Reques Faild with HTTP status 404:Not Found Pin
Theingi Win24-Sep-15 18:27
Theingi Win24-Sep-15 18:27 
BugError 500 when you publish my web.config Pin
PeterConchaR23-May-14 5:59
PeterConchaR23-May-14 5:59 
GeneralRe: Error 500 when you publish my web.config Pin
C. Augusto Proiete23-May-14 14:42
C. Augusto Proiete23-May-14 14:42 
QuestionVery helpful Pin
Andrew Fenster30-Aug-13 8:25
Andrew Fenster30-Aug-13 8:25 
AnswerRe: Very helpful Pin
C. Augusto Proiete23-May-14 14:42
C. Augusto Proiete23-May-14 14:42 
QuestionWhat happens to the maximum time allowed for timeouts Pin
thabomoj27-Mar-13 2:00
thabomoj27-Mar-13 2:00 
GeneralMy vote of 5 Pin
Nikhil_S8-Jan-13 1:59
professionalNikhil_S8-Jan-13 1:59 
nice article
GeneralRe: My vote of 5 Pin
C. Augusto Proiete23-May-14 14:43
C. Augusto Proiete23-May-14 14:43 
GeneralMy vote of 5 Pin
Sweetynewb1-Aug-12 1:14
Sweetynewb1-Aug-12 1:14 
GeneralRe: My vote of 5 Pin
C. Augusto Proiete23-May-14 14:43
C. Augusto Proiete23-May-14 14:43 
GeneralMy vote of 5 Pin
Angelinena16-Mar-12 5:33
Angelinena16-Mar-12 5:33 
GeneralRe: My vote of 5 Pin
C. Augusto Proiete23-May-14 14:43
C. Augusto Proiete23-May-14 14:43 
GeneralMy vote of 5 Pin
Wild-Programmer28-Dec-10 16:49
Wild-Programmer28-Dec-10 16:49 
GeneralRe: My vote of 5 Pin
C. Augusto Proiete23-May-14 14:43
C. Augusto Proiete23-May-14 14:43 
Generallogin.aspx Pin
Ajay Kale New27-Sep-10 0:13
Ajay Kale New27-Sep-10 0:13 
GeneralUseful Pin
mbaocha6-May-09 16:53
mbaocha6-May-09 16:53 
GeneralUploading files greater then 5 mB and timeout issue Pin
digitally_urs24-Jul-05 2:56
digitally_urs24-Jul-05 2:56 
GeneralCommon Problem Pin
oykica30-Jun-05 4:57
oykica30-Jun-05 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.