For Asp.net, only 2 MB files can be uploaded by default. The following configuration is added in Web. config. You can customize the maximum file size.
<Httpruntime
Executiontimeout = "300"
Maxrequestlength = "40960"
Usefullyqualifiedredirecturl = "false"/>
Sometimes this setting does not solve the problem. We have encountered one or more problems when uploading large files. Setting a large maxrequestlength value does not completely solve the problem, because Asp.net blocks the entire file until it is loaded into the memory and then processes it. In fact, if the file is large, we often see that Internet Explorer displays "the page cannot be displayed-cannot find server or DNS error". It seems that this error cannot be caught. Why? Because this is a client side error, application_error on the server side cannot be handled. If the following error occurs:
Handling server error when Upload File too large
The solution is to use the implicit httpworkerrequest and its getpreloadedentitybody and readentitybody methods to read data from the pipe created by IIS for Asp.net in blocks.
iserviceprovider provider = (iserviceprovider) httpcontext. current;
httpworkerrequest wR = (httpworkerrequest) Provider. getservice (typeof (httpworkerrequest);
byte [] BS = Wr. getpreloadedentitybody ();
....
If (! Wr. isentireentitybodyispreloaded ()
{< br> int n = 1024;
byte [] bs2 = new byte [N];
while (WR. readentitybody (bs2, n)> 0)
{< br> .....
}< BR >}