I have developed a large file upload using ASP. NET.CodeBecause it was developed under net1.1 and found that it could not be run under net.20, the problem was solved a few days ago. Now we have sorted out the entire development process for your reference. Because of the large amount of content, I plan to write it in six articles. The first article describes the problems to be solved and the general solutions, use four more articles to write down the four main problems that need to be solved during development, and then write a component usage method.
You can click here to downloadSource code.
Use ASP. net when uploading files, IIS receives the request content and sends it to ASP. and ASP. NET. net ISAPI loads all the read content into the server memory (when the request content is large, net2.0 will be stored in a temporary file, see the development instructions below). When uploading files, it consumes many server resources, so ASP.. Net has a limit on the size of the uploaded files, and the upload progress cannot be displayed. In practice, we often upload large files. In this case, you can modify the configuration file to set the maximum length to a large value, the server will consume a large amount of memory.
Therefore, if you can send the content sent by the client to ASP. net pipeline, as the server receives the content, the file content is written to the server disk, and then in ASP. in the. NET pipeline, only the corresponding form content of the request is put. In this way, the size limit of ASP. NET files can be avoided, and the server receiving progress can be displayed.
ASP. NET provides the httpmodule function and the means for users to process customer requests. To implement the httpmodule function, users only need to implement the system. Web. ihttpmodule interface. System. web. ihttpmodule defines two methods: void Init (httpapplication context) and void dispose (). The init method provides us with a parameter of the type httpapplication. In this httpapplication type, we provide processing ASP. NET page lifecycle events (For details, refer to msdn), we only need to process data in the earliest event beginrequest to avoid ASP.. net.
In order not to change ASP. NET page processing logic, we need to provide the file content, the other request content is correctly encapsulated to ASP. to this end, we need to analyze the specific format of the content sent from the client to the server. We can use other tools to provide the content, which is roughly as follows:
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "uploadid"
De858d87-e8b8-4f7a-a832-357da2efdf13
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "_ viewstate"
/Clusters/moe0enkotgfxmk
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "textbox1"
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "textbox2"
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "file1"; filename = "C: \ Documents ents and Settings \ Administrator \?????? \ Componentart.web.ui.rar"
Content-Type: Application/X-Rar-compressed
Rar! ?? S here I have removed the specific content of the file. After we extract the file, we mail it to ASP. NET, that is, the content after removing this part.
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "button1"
Start upload
----------------------------- 7d81e441d025c
Content-Disposition: Form-data; name = "_ eventvalidation"
/Keys =
----------------------------- 7d81e441d025c --
Pay attention to the red comments section, where the original content of the uploaded file is sent to ASP. net should be removed after the file content, so that the page control value, page events will be correctly sent to ASP.. NET page. Only the page cannot correctly obtain the content of the uploaded file.
There are three other problems: first, how to obtain the file content, how to determine that part of the content is the content of the uploaded file, not the content of other controls on the page; second: how can we make ASP. NET page to get the file correctly; 3: How do we mail the modified content to ASP. net, so that it does not feel that we have extracted the file content.
As long as the above three problems are solved, the large file upload problem is solved, and finally the progress is displayed, because there are many contents, I will introduce these three problems and display their progress in four parts.
To be continued...