2011-11-17 81 views
1

我有一个处理程序,它应该为它提供下载。这是重要的代码:ASP.net c#部分获取请求

// 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地址。深入挖掘后,看起来他们是使用下载Resumer软件的用户。

当我尝试使用下载resumer时,它似乎失败。我的问题是:

  • 如何检测这部分请求
  • 我怎么能起到部分请求
  • 我怎样才能使它与上面的代码工作,所以一)呼吁https://www.scirra.com/downloads/releases/construct2-r68-setup_4.exe在它第一部分得到和b)在最后部分得到电话completeReleaseDownload
+0

我认为这会回答你的问题 http://stackoverflow.com/questions/5429947/supporting-resumable-http-downloads-through-an-ashx-handler –

回答

2

这在哑剧与E-标签实现的,请上网:http://www.devx.com/dotnet/Article/22533/1954

当你捕捉使用DownloadResumer发送一些数据包,你可能会发现所指定的范围标记。

范围:字节= 500-1000

这允许你并检查这是否是一个局部请求如果是这样,采取样作用:

布尔isFirstRequest =的RangeStart == 0; bool isLastRequest = RangeEnd == file.TotalBytes;

希望这有助于