I’ve got a C# page that’s generating a PDF file and returning it to the user. I’m explicitly setting the Content-Type header to “application/pdf” and the MIME Type is registered in IIS, yet IIS seems to be stripping off the Content-Type.
The file is being returned correctly and if I choose to save it to disk I can open it just fine. If I run the page from the ASP.NET Development Server the Content-Type header comes through just fine.
The code…
byte[] pdf = //magic!
string filename = "Some.pdf";
Response.Clear();
Response.ClearHeaders();
//This way didn't work either...
//Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ";size=" + pdf.Length.ToString());
Response.Flush();
Response.BinaryWrite(pdf);
Response.Flush();
Response.End();
I have something very similar currently up and running (it lets user download a TXT file generated in the code behind itself).
Same code as yours basically but I don’t have
Response.Flush()anywhere. You might try commenting both.Flushes out and see what happens.edited this is my code (successfully lets the user download a TXT file