Resolve asp.net upload file size limit

Source: Internet
Author: User
Tags file size
Asp.net| Solution | upload
For ASP.net, the default is to upload only 2M files, add the following configuration, you can generally customize the maximum file size.
executiontimeout= "300"
Maxrequestlength= "40960"
Usefullyqualifiedredirecturl= "false"/>

If not, you can use the scenario provided by Shi:
We have had this or that problem when uploading large files. Setting a large maxRequestLength value does not completely solve the problem, because ASP.net blocks until the entire file is loaded into memory and then processed. In fact, if the file is very large, we often see Internet Explorer display "The page cannot be displayed-cannot find server or DNS error", as if it could not catch this error 。 Why? Because this is a client side error, the server side end of the Application_Error is not processed, 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 implied httpworkerrequest, using its getpreloadedentitybody and Readentitybody methods to read data from the pipe built by IIS for asp.net
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 a solution (with HttpModule) that allows you to upload a large file in real time, as well as upload progress:
asp.net Upload Magic Part 2
Here are the PPT files for his lectures:
Uploading with asp.net (Part 1)
Uploading with asp.net (Part 2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.