我们有这段代码用于提供下载:
public class downloadRelease : IHttpHandler {
public void ProcessRequest (HttpContext context) {
-- snip --
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + OriginalFileName);
context.Response.WriteFile(Settings.ReleaseFileLocation + ActualFileName);
// Log download
Constructor.VersionReleaseDownload.NewReleaseDownload(ActualFileName);
它能正常工作,除了日志下载代码似乎会在下载开始时立即运行,而不是当我们期望的下载完全完成后再运行。
有人能解释一下为什么会这样,并且如何更改它以便只在完成时记录日志吗? 我们不想计算部分下载。
context.Response.AddHeader("Content-Length", FileSize.ToString());
- Tom Gullen