0

This is not solved by ASP.NET file download from server (6 answers)

I am trying to Redirect to a pdf file using Reponse.Redirect(pdfurl). The web application uses ASP.NET, JQuery, C# and AJAX Toolkit.

This works for the majority of the pdfs the application creates, however for certain ones, the page does not get redirected and on the console I get the error

Failed to load resource: net::ERR_EMPTY_RESPONSE.

The only difference from the pdfs that work and the ones that don't seem to be size. The ones that work are approx 2.5KB and the ones that don't are 4.6KB.

The Redirect works when I run the App locally, however I get the error when I run over the network. I have tried bumping up all the timeouts I can see, but still getting the error.

I looked at ASP.NET file download from server and changed my code to the following

<%@ WebHandler Language="C#" Class="DownLoadFile" %>

using System;
using System.Web;
using System.IO;

public class DownLoadFile : IHttpHandler {

public void ProcessRequest (HttpContext context)
{
    System.Web.HttpRequest request = System.Web.HttpContext.Current.Request;
    string yourVariableValue = request.QueryString["yourVariable"];

    if (!string.IsNullOrEmpty(yourVariableValue))
    {
        HttpResponse response = System.Web.HttpContext.Current.Response;
        response.ClearContent();
        response.Clear();
        response.ContentType = "application/PDF";
        response.AddHeader("Content-Disposition",
                           "attachment; filename=" + Path.GetFileName(yourVariableValue) + ";");
        response.Redirect(yourVariableValue);
        response.Flush();
        response.End();
    }
}

public bool IsReusable {
    get {
        return false;
        }
    }
}

I call this by -

string handlerUrl = @"~/DownLoadFile.ashx?yourVariable=" + theReportName;
Response.Redirect(handlerUrl);

I still get the error Failed to load resource: net::ERR_EMPTY_RESPONSE. for certain large pdfs.

An example of the pdf url is

"~/Secure/GraphBin/Reports/yei3k3msbctxeo3som4w0jse/297f489d-7a41-4098-883e-264b82e61d8e/Quarterly Report Q3 2019.pdf"

Can anyone help me please?

Thanks

UPDATE

I changed the redirect to an aspx page, but still got the same error!

Could it be a Timeout issue that I have missed?

I bumped up the execution timeout in my web.config file to no avail.

<httpRuntime maxRequestLength="2000000000" executionTimeout="999999" />
Kev
  • 109
  • 1
  • 11
  • hmm, i have never used a Response.Redirect to a file like that. Try to load the file bytes into c# then use Response.BinaryWrite() or try Response.TransmitFile(filePath) or play with config settings for maxRequestLength, etc. – Ryano Jan 30 '20 at 13:47
  • Hi Ryano. Changed the Response.Redirect to TransmitFile and then tried BinaryWrite. Both of them made no difference. Done some more testing and I don't think it is necessarily failing because I am trying to redirect to a pdf. I changed to redirect to a aspx page and still got the same error. – Kev Jan 30 '20 at 16:02

0 Answers0