C# 解决HTTP2下载失败的网络错误

C# 解决HTTP2下载失败的网络错误,c#,asp.net,http2,iis-10,C#,Asp.net,Http2,Iis 10,环境 ASP.NET网站 .NET 4.6.1 托管在Windows Server上的IIS 10.0中 2016年 Web.Config: <modules runAllManagedModulesForAllRequests="true"> <remove name="FormsAuthentication" /> </modules> protected void btnDownload_Click(object sender, System.

环境

  • ASP.NET网站
  • .NET 4.6.1
  • 托管在Windows Server上的IIS 10.0中 2016年
Web.Config:

<modules runAllManagedModulesForAllRequests="true">
  <remove name="FormsAuthentication" />
</modules>
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; }
}
问题: 在第一次回发时,浏览器使用其协议的HTTP2,下载失败。Chrome站点“网络错误-下载失败”

再次单击同一链接,协议返回到http/1.1,下载成功

  • 当前语法对于在HTTP2下传递文件有效吗
  • 可以在IIS10/ASP.NET 4.6.1中强制使用http/1.1吗
我们有完全相同的问题!这只发生在Chrome上,我们暂时禁用了服务器上的HTTP/2,直到我们能够解决问题为止。我已经用HTTPS将SSRS移动到了一个新的服务器上,当下载报告时,它给了我这个问题。添加HttpContext.Current.Response.End();冲水后,它工作得很好!