IE comes not download function HTTP functionality to implement HTTP functionality, need to use the HTTP protocol headers and little-known several response request header.
A . Two heads in response to necessary the Accept-Ranges , the ETag
Each time you submit the client download request, the server must add these two response header to ensure that the client and server to identify this download to download can resume:
Ranges-the Accept : This is to inform the client to download a resume can resume the download, storage start byte position This download, the byte size of the file;
The ETag : uniquely identifies the saved file (I am using the filename + file was last modified, in order to resume the file validation request);
Modified-Last : Alternatively response header, storing the last modified time of the file server, for verifying
Two . An important request header Range
The Range : download first time, the Range header of null , this time in response to the first server response header must be added to the Accept-Ranges , the ETag ;
When the resume request, which value represents the number of bytes that the client has received, i.e. This download start byte position of the server based on the value of the read data is sent to the client from the position.
Three . Request for validation head the If-the Range ,
When the response header contains the Accept-Ranges , the ETag when the resume request time, the request header including these:
The Range-IF : corresponding to the response header ETag value;
-Modified-Since The unless : the corresponding response header Last-Modified value.
When the resume request, in order to ensure consistency and correctness of the documents the client and server, it is necessary to file validation, verification need to write validation code on these two values request header parsing, the client has been downloaded parts and service side of the file comparison, if not match, download it from the beginning, if the agreement is HTTP.
Four . Speed limit
Program to add the speed limit for the client limit traffic access control.
Five . Other Considerations
Such as: file name garbled problem, change the file name plus the spaces, to force the client to display download dialog boxes, see the source code comments:
1
2 /// <summary>
3 /// download files, support for large files, resume, speed limit. Accept-Ranges response header supports the resume, ETag, request headers Range.
4 /// the Accept-Ranges : response header to indicate to the client, this process supports download resume realize Background Intelligent Transfer Service (BITS), is:. Bytes;
. 5 /// the ETag : response header for the initial response to the client (200), and a resume request from the client,
6 /// must provide a unique ETag value (by file name and last modified date of composition) for each file, which allows the client software to verify that they have been downloaded byte block is still up to date.
. 7 /// the Range : resume start position, i.e., the number of bytes have been downloaded to the client, such as a value: bytes = 1474560-.
8 /// further: converting spaces UrlEncode encoded in the file name will + (converted to% 2b), but the browser is not understood plus spaces, so the browser downloaded file space on into a plus sign;
9 /// Solution: After UrlEncode, the "+" replaced by "20%" because the browser will be 20% converted to spaces
10 /// </summary>
. 11 /// <param name = "httpContext"> current request HttpContext </ param>
12 is /// <param name = "filePath"> physical path of the download file, including the path, file name </ param>
13 is /// <param name = "Speed"> bytes per second allows downloading </ param>: download speed
14 /// <returns A> to true download is successful, false download fails </ returns>
15 public static bool DownloadFile(HttpContext httpContext, string filePath, long speed)
16 {
17 bool right = true;
18 try
19 {
20 - verification: HttpMethod, if the requested file exists
36
37 define local variables
49
50 - Authentication: file is too large, whether it is resuming, and has not been altered after the date of the last requested --------------
67
68 try
69 {
70 ------- add significant response header, header resolution request, the correlation verifier -------------------
97
98 ------- transmission data block to the client -------------------
108 }
109 catch
110 {
111 ret = false;
112 }
113 finally
114 {
115 br.Close();
116 myFile.Close();
117 }
118 }
119 catch
120 {
121 ret = false;
122 }
123 return ret;
124 }
上传展示截图:
详细配置信息可以参考我写的这篇文章:http://blog.ncmem.com/wordpress/2019/08/09/net%E6%96%AD%E7%82%B9%E7%BB%AD%E4%BC%A0/