In ASP. NET, the maximum file to be uploaded may be less than MB, and the file size cannot be changed.
The default upload size is 4 MB.
To upload a larger file, you must use other methods. for example, FTP, or other components such as aspupload (I don't know if there is any net version), and the following address discusses uploading super large files in net. You can check it out.
The following are some materials. You can refer to them (the address above is also in it)
For Asp.net, only 2 MB files can be uploaded by default. The following configuration is added. You can customize the maximum file size.
<Httpruntime
Executiontimeout = "300"
Maxrequestlength = "40960"
Usefullyqualifiedredirecturl = "false"/>
If not, you can use the solution provided by Si Gui:
We 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 processed. 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,
You can refer to this post to study the mechanism of this error.
Handling server error when Upload File too large
The solution is to use the implicit httpworkerrequest, and use its getpreloadedentitybody and readentitybody methods to create an ASP. NET
Multipart Data Reading in Pipe
Iserviceprovider provider = (iserviceprovider) httpcontext. Current;
Httpworkerrequest wR = (httpworkerrequest) provider. getservice (typeof (httpworkerrequest ));
Byte [] BS = Wr. getpreloadedentitybody ();
....
If (! Wr. isentireentitybodyispreloaded ())
{
Int n = 1024;
Byte [] bs2 = new byte [N];
While (WR. readentitybody (bs2, n)> 0)
{
.....
}
}
Chris Hynes provides us with such a solution (using httpmodule) that allows you to upload large files and display the upload progress in Real Time:
ASP. NET upload magic part 2
Here is the pptfile of his lecture:
Uploading with ASP. NET (Part 1)
Uploading with ASP. NET (Part 2)
In this project, a large file upload is used, and the number of files to be uploaded is more than 100 MB.
The component found that many of them used two controls: aspnetupload 2.0 and Lion. Web. uploadmodule. In addition, they thought about its blog.
The way mentioned in http://blog.joycode.com/saucer/archive/2004/03/16/16225.aspx
The two controls use the implicit httpworkerrequest method to read data from the pipe created for ASP. NET by using its getpreloadedentitybody and readentitybody method. Chris Hynes provides us with such a solution (using httpmodule) that allows you to upload large files and display the upload progress in real time.
Lion. Web. uploadmodule and aspnetupload both use this solution.
When the leaflet file is used, the two software methods are the same, inheriting the httpmodule
Httpapplication application1 = sender as httpapplication;
Httpworkerrequest request1 = (httpworkerrequest) (iserviceprovider) httpcontext. Current). getservice (typeof (httpworkerrequest ));
Try
{
If (application1.context. Request. contenttype. indexof ("multipart/form-Data") <=-1)
{
Return;
}
// Check the hasentitybody
If (! Request1.hasentitybody ())
{
Return;
}
Int num1 = 0;
Timespan span1 = datetime. Now. Subtract (this. begintime );
String text1 = application1.context. Request. contenttype. tolower ();
Byte [] buffer1 = encoding. ASCII. getbytes ("\ r \ n --" + text1.substring (text1.indexof ("boundary =") + 9). tochararray ());
Int num2 = convert. toint32 (request1.getknownrequestheader (11 ));
Progress progress1 = new progress ();
Application1.context. Items. Add ("filelist", new hashtable ());
Byte [] buffer2 = request1.getpreloadedentitybody ();
Num1 + = buffer2.length;
String text2 = This. analysepreloadedentitybody (buffer2, "uploadguid ");
If (text2! = String. Empty)
{
Application1.context. Items. Add ("lionsky_uploadmodule_uploadguid", text2 );
}
Bool flag1 = true;
If (num2> This. uploadfilelength () & (0> span1.totalhours) | (span1.totalhours> 3 )))
{
Flag1 = false;
}
If (0> span1.totalhours) | (span1.totalhours> 3 ))
{
Flag1 = false;
}
String text3 = This. analysepreloadedentitybody (buffer2, "uploadfolder ");
Arraylist list1 = new arraylist ();
Requeststream stream1 = new requeststream (buffer2, buffer1, null, requeststream. filestatus. Close, requeststream. readstatus. noread, text3, flag1, application1.context, String. Empty );
List1.addrange (stream1.readbody );
If (text2! = String. Empty)
{
Progress1.filelength = num2;
Progress1.ededlength = num1;
Progress1.filename = stream1.originalfilename;
Progress1.filecount = (hashtable) application1.context. items ["filelist"]). count;
Application1.application ["_ uploadguid _" + text2] = progress1;
}
If (! Request1.isentireentitybodyispreloaded ())
{
Byte [] buffer4;
Arraylist list2;
Int Number3 = 204800;
Byte [] buffer3 = new byte [num3];
While (num2-num1)> = num3)
{
If (! Application1.context. response. isclientconnected)
{
This. clearapplication (application1 );
}
Num3 = request1.readentitybody (buffer3, buffer3.length );
Num1 + = num3;
List2 = stream1.contentbody;
If (list2.count> 0)
{
Buffer4 = new byte [list2.count + buffer3.length];
List2.copyto (buffer4, 0 );
Buffer3.copyto (buffer4, list2.count );
Stream1 = new requeststream (buffer4, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename );
}
Else
{
Stream1 = new requeststream (buffer3, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename );
}
List1.addrange (stream1.readbody );
If (text2! = String. Empty)
{
Progress1.ededlength = num1;
Progress1.filename = stream1.originalfilename;
Progress1.filecount = (hashtable) application1.context. items ["filelist"]). count;
Application1.application ["_ uploadguid _" + text2] = progress1;
}
}
Buffer3 = new byte [num2-num1];
If (! Application1.context. response. isclientconnected & (stream1.fstatus = requeststream. filestatus. Open ))
{
This. clearapplication (application1 );
}
Num3 = request1.readentitybody (buffer3, buffer3.length );
List2 = stream1.contentbody;
If (list2.count> 0)
{
Buffer4 = new byte [list2.count + buffer3.length];
List2.copyto (buffer4, 0 );
Buffer3.copyto (buffer4, list2.count );
Stream1 = new requeststream (buffer4, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename );
}
Else
{
Stream1 = new requeststream (buffer3, buffer1, stream1.filestream, stream1.fstatus, stream1.rstatus, text3, flag1, application1.context, stream1.originalfilename );
}
List1.addrange (stream1.readbody );
If (text2! = String. Empty)
{
Progress1.receivedlength = num1 + buffer3.length;
Progress1.filename = stream1.originalfilename;
Progress1.filecount = (hashtable) application1.context. items ["filelist"]). count;
If (flag1)
{
Progress1.uploadstatus = progress. uploadstatusenum. Uploaded;
}
Else
{
Application1.application. Remove ("_ uploadguid _" + text2 );
}
}
}
Byte [] buffer5 = new byte [list1.count];
List1.copyto (buffer5 );
This. populaterequestdata (request1, buffer5 );
}
Catch (exception exception1)
{
This. clearapplication (application1 );
Throw exception1;
}
The method mentioned by the author can also upload large files using mime, and download it at the following address:
Http://krystalware.com/files/slickupload.zip
However, it is much easier to think about it.
More: http://community.csdn.net/Expert/topic/4093/4093569.xml? Temp =. 9714624.