ASHX Handler sends pdf file as a text document

470 Views Asked by At

From an ashx handler, I am trying to send a pdf file. However, the pdf file is being downloaded with a .txt extension on the browser.

I can verify that the file name which i set is .pdf. On checking Developer tools in Mozilla, I find that in response headers, the content-type is text-plain. which should not be as i am explicitly setting content-type as seen below ( I have tried both octet-stream as well as application/pdf). Also the filename turns out to be .pdf.txt when i save the file.

 context.Response.Clear();
                context.Response.ClearContent();
                context.Response.ClearHeaders();

                context.Response.ContentType = "application/octet-stream";// "application /pdf";
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(GenPDFFileName));
                context.Response.TransmitFile(GenPDFFileName);
                context.Response.SuppressContent = true;
                context.Response.End();

Please let me know how do i resolve this.

OK Checked it Today : This happens only in firefox. Chrome & IE work as desired

0

There are 0 best solutions below