asp.net large file Upload development summary

Source: Internet
Author: User

Previously developed a large file with ASP.net code, because it was developed under the NET1.1, found that can not run under the net.20, the last few days to solve the problem, now the whole development process to tidy up for your reference. Because the content is more, so I intend to divide into six articles to write, the first write the question which needs to solve and the general solution idea, then use four article to write down the four main problems which need to solve in the development, finally write a component to use method.

You can click here to download the NET1.1 source code.

1, the question puts forward:
Using asp.net when uploading files, IIS receives the requested content and sends it to the ASP.net pipeline, and then the ASP.net ISAPI reads all of the contents into the server memory (NET2.0, when the request content is large, is stored in the temporary file, see the development instructions later), When uploading files, consumes more server resources, so asp.net to upload file size will be limited, and can not provide upload progress display. And we in the actual application, often will upload the phenomenon of large files, at this time, you can modify the configuration file will be the largest length configuration set very large, but in this way, the server will consume a lot of memory.

To do this, if IIS sends the content sent by the client to the ASP.net pipeline, the contents of the file are written to the server disk while the server receives the content, and then only the corresponding form contents of the request are placed in the ASP.net pipeline. This avoids the asp.net upload file size limit, while providing the server receive progress display.

2, the solution analysis:
asp.net provides HttpModule functionality, provides users with the means to handle customer requests, to achieve HttpModule functionality, users only need to implement the System.Web.IHttpModule interface. The System.Web.IHttpModule defines two methods void Init (HttpApplication context) and void Dispose (). The Init method gives us an argument with a type of HttpApplication, in this HttpApplication type, Provides us with the various events that occur during the lifecycle of the ASP.net page (please refer to MSDN), we only need to handle data reception in the earliest event beginrequest to avoid the asp.net maximum request length limit.

In order not to change the asp.net to the page processing logic, we need to provide the contents of the file, the other request content to properly encapsulated to asp.net, so we need to analyze the client sent to server-side content of the specific format, we can use other tools to provide these content, which are roughly as follows:

7d81e441d025c

Content-disposition:form-data; Name= "Uploadid"



De858d87-e8b8-4f7a-a832-357da2efdf13

7d81e441d025c

Content-disposition:form-data; Name= "__viewstate"



/wepdwulltiwode1otkzntupzbycagmpfgieb2vuy3r5cgufe211bhrpcgfydc9mb3jtlwrhdgfkzaq0pcd9kisz7/moe0enkotgfxmk

7d81e441d025c

Content-disposition:form-data; Name= "TextBox1"



7d81e441d025c

Content-disposition:form-data; Name= "TextBox2"



7d81e441d025c

&nb</

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.