How to solve the file upload size limit in ASP. NET

Source: Internet
Author: User
# Re: URL Processing two gadgets reply how to solve ASP. net file upload size restrictions, we know that by default ASP.. Net file upload size is limited to 2 MB. In general, we can change the web. the config file defines the maximum file size as follows:
<Httpruntime executiontimeout = "300" maxrequestlength = "40960" usefullyqualifiedredirecturl = "false"/> in this way, the maximum value of the uploaded file is 4 MB, however, this does not allow us to infinitely expand the value of maxrequestlength, because ASP. net loads all files into the memory and then processes them. 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. The implementation method is as follows:
Iserviceprovider provider = (iserviceprovider) httpcontext. Current;
Httpworkerrequest wR = (httpworkerrequest) provider. getservice (typeof (httpworkerrequest ));
Byte [] BS = Wr. getpreloadedentitybody ();
.
If (! Wr. isentireentitybodyispreloaded ())
{
INTN = 1024;
Byte [] bs2 = newbyte [N];
While (WR. readentitybody (bs2, n)> 0)
{
..
}
} This solves the problem of uploading large files. Thin comments on

Http://www.cnblogs.com/pw/archive/2006/05/24/408427.html

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.