ASP.NET MVC:大型PDF下载失败,但大型zip成功下载

时间:2018-06-21 10:44:36

标签: c# asp.net-mvc pdf iis

我写了一个代码来下载大(约160 MB)PDF文件。我可以在本地环境中下载大型PDF文件,没有任何问题,但在生产环境中同样会失败。该应用程序还具有压缩文件然后下载的功能,现在在生产中可以完美运行。我可以下载PDF文件的zip文件(zip文件大小:157 MB),并且zip文件的大小与PDF文件的大小大致相同。 错误:单击链接后,开始下载PDF文件,然后在chrome浏览器中显示“网络错误”消息,从而中断了下载过程。在IE浏览器中的消息是:“ test.pdf下载被中断”。 我进行了很多搜索,但找不到与我的问题相关的内容。任何人都可以帮助查找为什么出现“网络错误”消息而导致失败的问题是什么?

下面是我下载PDF文件时的代码:

//------ this code goes into web tier ------------
public FileResult DownloadFile(int FilePk, string fileName)
{
        try
        {
             //Clear Browser Header Cache
                var browserInformation = Request.Browser;
                Response.ClearHeaders();
                //Set as private if current browser type is IE
                Response.AppendHeader("cache-control", browserInformation.Browser == "IE" ? "private" : "no-cache");

            var pdfFileByte = MyWCFService.GetFile(FilePk); // this service returns byte[]
            return statement.IsNull() ? null : File(pdfFileByte, "Application/pdf", "File-" + "fileName" + ".pdf");
        }
        catch (Exception ex)
        {
            OnException(ex);
        }

        return null;
    }
//----- this code goes into wcf service which is on app tier---
public byte[] GetFile(int FilePk)
    {
        // Here decalre string filepath variable and get value into it using path present in database
        var fi = new FileInfo(filePath);

        if (!fi.Exists) return null;

        var fileSize = (int)fi.Length;
        var fileInByte = new byte[fileSize];
        using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        {
            fs.Read(fileInByte, 0, fileSize);
        }
        return fileInByte;
    }

下面是我下载zip文件时的代码:

 //------ this code goes into web tier ------------
public FileResult DownloadFileForAll(int exrqPk, string userFileName)
    {
        try
        {

           //Clear Browser Header Cache
                var browserInformation = Request.Browser;
                Response.ClearHeaders();
                //Set as private if current browser type is IE
                Response.AppendHeader("cache-control", browserInformation.Browser == "IE" ? "private" : "no-cache");
            var statement = MyWCFService.GetFileAll(exrqPk);
            return statement.IsNull() ? null : File(statement, "application/zip", userFileName + ".zip");
        }
        catch (Exception e)
        {
            OnException(e);
        }
        return null;
    }


----- this code goes into wcf service which is on app tier---
public byte[] GetFileAll(int exrqPk)
    {
        // Here decalre string filepath variable and get value into it using path present in database
        var fi = new FileInfo(filePath);

        if (!fi.Exists) return null;

        var fileSize = (int)fi.Length;
        var fileInByte = new byte[fileSize];
        using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        {
            fs.Read(fileInByte, 0, fileSize);
        }
        return fileInByte;
    }

0 个答案:

没有答案
相关问题