Using ASP.NET to upload large files
We have encountered such or such problems when we last. Setting big maxRequestLength values do not completely solve the problem, because the ASP.NET will block until the entire file is loaded into memory. In fact, if the files are large, we often see Internet Explorer display "The page cannot be displayed - cannot Find Server or DNS ERROR", it seems to be Catch can't. why? Because this is a Client Side error, the Application_ERROR of the Server Side is not processed, and you can refer to this post to study the mechanism of generating 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 read data from 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 (writhenTityBody (BS2, n)> 0) {.....}}
Chris Hynes offers us a solution (with httpmodule), which can display upload progress in real time in addition to allowing you to upload large files:
ASP.NET UPLOAD MAGIC PART 2
Here is the PPT file of his lecture:
UPLoading with asp.net (Part 1)
Uploading with asp.net (Part 2)