下载25MB文件时出现问题 - 8MB文件下载没有问题(ASP.NET)

时间:2010-07-01 03:46:28

标签: asp.net download

我在同一个位置有两个文件但是大文件即将完成下载时会出错(在IE和Firefox中都有)。

我使用以下代码:

public static void DownloadZipFile (string filename, bool notifyMe)
{
    HttpContext context = HttpContext.Current;
    HttpServerUtility server = context.Server;
    bool ok = false;
    try
    {
        string file = string.Format ("~/contents/licensing/members/downloads/{0}", filename);
        string server_file = server.MapPath (file);

        HttpResponse response = context.Response;
        //response.BufferOutput = false;
        response.ContentType = "application/zip";
        string value = string.Format ("attachment; filename={0}", filename);
        response.AppendHeader ("Content-Disposition", value);
        FileInfo f = new FileInfo (server_file);
        long size = f.Length;
        response.TransmitFile (server_file, 0, size);
        response.Flush ();
        ok = true;
        response.End ();
    }
    catch (Exception ex)
    {
        Utilities.Log (ex);
    }
    finally
    {
        if (ok && notifyMe)
            NotifyDownload (filename);
    }
}

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

Response.End()调用Response.Flush()。尝试删除Flush呼叫。

答案 1 :(得分:0)

此问题的解决方案是添加以下行:

response.AddHeader("Content-Length",size.ToString());

在调用TransmitFile()之前。 学分归Jim Schubert所有(见上面的评论)。