14

Environment

  • ASP.NET website
  • .NET 4.6.1
  • Hosted in IIS 10.0 on Windows Server 2016.

Web.Config:

<modules runAllManagedModulesForAllRequests="true">
  <remove name="FormsAuthentication" />
</modules>

Button Click:

protected void btnDownload_Click(object sender, System.EventArgs e)
{
    try
    {
        string sPDFFilename = "doc.pdf";    
        byte[] data = GetData();            
        Response.ClearHeaders();
        Response.ClearContent();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "Attachment; filename=" + sPDFFilename);
        Response.AddHeader("content-length", (data.Length.ToString()));
        Response.BinaryWrite(data);
        Response.Flush();
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    catch(Exception ex){ throw; }
}

Question: On the first post back the browser use's HTTP2 for its protocol and the download fails. Chrome sites "Network Error - Failed to Download"

Click the same link again and the protocol falls back to http/1.1 and the download is successful.

  • Is the current syntax valid for delivering a file under HTTP2?
  • Is it possible to force http/1.1 in IIS10/ASP.NET 4.6.1?
Dale K
  • 25,246
  • 15
  • 42
  • 71
  • We have the exact same problem! It only happens in Chrome. – Morten OC Aug 20 '17 at 12:24
  • 2
    We wound up disabling the HTTP/2 on the server for the time being until we can resolve our issue. https://stackoverflow.com/questions/31668151/how-to-disable-http-2-on-iis-of-windows-10 – seewhathadhappenedwas Sep 07 '17 at 17:24
  • I have moved an SSRS to a new server with HTTPS, and when downloading the reports it gave me this problem. Adding HttpContext.Current.Response.End(); after the Flush() it works perfectly! – AlvaroV Mar 22 '21 at 13:06
  • HKLM\System\CurrentControlSet\Services\HTTP\Parameters add dword Http2MaxConcurrentClientStreams value 100 – Shaybakov Jun 19 '21 at 17:56

1 Answers1

0

In HTTP2, most browsers will fail to parse the filename if it contains non US-ASCII characters. HTTP1.1 implementations are more lenient with that.

To still support utf-8 filenames you can use filename* attribute with url encoded value.

Currently the most supported Content-Disposition format is:

attachment; filename="<us-ascii filename>"; filename*=utf-8''<url-encoded-utf-8-filename>

ie.

attachment; filename="EURO rates"; filename*=utf-8''%e2%82%ac%20rates