I have a page in my site which generates a PDF report dynamically on the server whilst displaying a "please wait" message to the users browser. After it has finished it puts the unique filepath in the session and then opens up download.aspx which is empty bar the following c# code in the page_load function.
string fileUID = (string)(Session["fileUID"]);
string FilePath = @fileUID;
byte[] fileBytes = System.IO.File.ReadAllBytes(FilePath);
string sFileName = "Report.pdf";
System.Web.HttpContext context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.AppendHeader("content-length", fileBytes.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("content-disposition", "attachment; filename=" + sFileName);
context.Response.BinaryWrite(fileBytes);
context.Response.Flush();
System.IO.File.Delete(FilePath);
context.ApplicationInstance.CompleteRequest();
In IE this brings up the download dialogue allowing the user to download the file. However in chrome, firefox and safari it just sits on the please wait page forever...
I have also tried specifying the mime type for a PDF file, and not specifying content-disposition to make the PDF display in the browser window, again works perfectly in internet explorer but not any other browser.
The issue occurs both when testing on localhost, and when uploaded to the server.
I have searched both on here and the wider world and cannot seem to find anybody else with the same issue.
Please can somebody show me the error of my ways.