谷歌浏览器不显示来自 asp.net 页面的 PDF

时间:2021-03-02 17:21:08

标签: asp.net google-chrome pdf asp.net-web-api

我想在带有按钮的 .aspx 页面上显示 pdf 文件。代码是这样的:

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、Edge。但它不适用于谷歌浏览器。可能有什么问题?你能帮我吗?

0 个答案:

没有答案