【问题标题】:ASP.net c# partial get requestASP.net c# 部分获取请求
【发布时间】:2011-11-17 05:27:18
【问题描述】:

我有一个处理程序,它可以正常工作以提供下载服务。这是重要的代码:

    // 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() 仅在下载完成时运行,这非常有用(re Only count a download once it's served

问题是,我们会在大约相同的时间间隔内收到大量来自相同 IP 地址的日志。在深入挖掘之后,他们似乎是使用 Download Resumer 软件的用户。

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

  • 如何检测这是部分请求
  • 如何处理部分请求
  • 如何使其与上述代码一起工作,以便 a) 在第一个部分 get 上调用 https://www.scirra.com/downloads/releases/construct2-r68-setup_4.exe,b) 在最后一个部分 get 上调用 completeReleaseDownload

【问题讨论】:

标签: c# asp.net http-headers download partial


【解决方案1】:

这是在 Mime 中通过 E-Tag 实现的,请查看: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)

【讨论】:

    猜你喜欢
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2018-04-06
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多