我有一个处理程序可以正常运行下载。这是重要的代码:
// Get size of file
FileInfo f = new FileInfo(Settings.ReleaseFileLocation + ActualFileName);
long FileSize = f.Length;
// Init (returns ID of tblDownloadLog record created with blank end date)
int DownloadRecordID = Constructor.VersionReleaseDownload.newReleaseDownload(ActualFileName);
context.Response.Clear();
context.Response.Buffer = false;
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + OriginalFileName);
context.Response.AddHeader("Content-Length", FileSize.ToString());
context.Response.TransmitFile(Settings.ReleaseFileLocation + ActualFileName);
context.Response.Close();
// Complete download log, fills out the end date
Constructor.VersionReleaseDownload.completeReleaseDownload(DownloadRecordID);
context.Response.Close();
确保completeReleaseDownload()
仅在下载完成时运行,这非常有用(重新Only count a download once it's served)
问题是,我们在大约相同的时间间隔内获得了来自同一IP地址的大量日志。在深入挖掘之后,看来他们是使用Download Resumer软件的用户。
当我尝试使用下载服务器时,它似乎失败了。我的问题是:
https://www.scirra.com/downloads/releases/construct2-r68-setup_4.exe
并在最后一次部分获取时调用completeReleaseDownload
?答案 0 :(得分:2)
这是通过带有电子标签的Mime实现的,请查看:http://www.devx.com/dotnet/Article/22533/1954
当您捕获使用DownloadResumer
发送的某些数据包时,您可能会发现指定了Range
标记。
Range: bytes=500-1000
这允许您检查这是否是部分请求,如果是,请执行以下操作:
bool isFirstRequest = RangeStart == 0;
bool isLastRequest = RangeEnd == file.TotalBytes - 1;//(Ranges use Zero-Based Indices)