2011-11-17 102 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;

希望這有助於