0

I want to display a pdf file on an .aspx page with a button. The codes is like that:

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 { }
        }

The codes works on Firefox, Edge. But it is not work on Google Chrome. What could be problem ? Can you help me ?

  • Is Chrome giving you an error? What does the network request status code look like when you check the browser's dev tools? Why do you have a line of code after Response.End? It will never get reached. – mason Mar 02 '21 at 17:39
  • Yes. When i click the code Chrome gives me the error like that: "This site is not accessible. The web page at https://massgrup.com/Raporlar.aspx may be temporarily unavailable or has been permanently moved to a new web address. ERR_HTTP2_PROTOCOL_ERROR" I can remove the code aftes Response.End – Oğuzhan Eker Mar 02 '21 at 19:32
  • What is the HTTP status code? Is there any other information in the developer tools? – mason Mar 02 '21 at 19:39
  • There is no information about the HTTP status code – Oğuzhan Eker Mar 02 '21 at 20:26
  • Have you reviewed [this question](https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about) and all of the answers there to see if any of them is applicable to you? Did you check the value of `ms.Length.ToString()` to ensure it gives you data in an appropriate format for that header? – mason Mar 02 '21 at 20:49
  • ms.Length.ToString() gives the value like 7688493. [link] (https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about) I check this question but this is not working – Oğuzhan Eker Mar 05 '21 at 06:30

0 Answers0