【发布时间】:2021-02-04 20:19:21
【问题描述】:
我想让用户显示一个 pdf 并将其保存在我的 asp.net 项目中。
我的代码如下:
string yol = e.CommandArgument.ToString();
string path = Server.MapPath("~/Raporlar/2021/" + yol.Trim());
WebClient User = new WebClient();
Byte[] s = User.DownloadData(path);
System.IO.MemoryStream ms = new System.IO.MemoryStream(s);
if (ms != null && ms.Length > 1)
{
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Charset = "UTF-8";
Response.Buffer = true;
Response.AddHeader("Content-Length", ms.Length.ToString());
Response.AddHeader("Content-Disposition", "inline; filename=\"" + yol + "\"");
Response.AddHeader("Expires", "0");
Response.AddHeader("Pragma", "cache");
Response.AddHeader("Cache - Control", "private");
Response.ContentType = "application/pdf";
Response.BinaryWrite(ms.ToArray());
Response.Flush();
try { Response.End();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
catch { }
}
显示按钮仅适用于 Firefox。其他浏览器(Google Chrome、Opera、Edge..)不显示 pdf 并给出如下错误:
嗯……此页面不可用。 https://massgrup.com/Raporlar.aspx 的网页可能遇到一些问题或已永久移动到新的网址。 ERR_HTTP2_PROTOCOL_ERROR
【问题讨论】:
标签: asp.net google-chrome pdf http-error