0

I am having a user who is reporting that files are being displayed as raw data in his browser. He uses Internet Explorer.

The files are being served via a .ashx handler file and it has been working until.

This is the relevant part of my .ashx handler:

context.Response.Clear()
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name)
context.Response.AppendHeader("Content-Length", size.ToString)
context.Response.ContentType = "application/pdf"
context.Response.TransmitFile(fullname)
context.Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()

Can anyone figure something out of this screenshot? enter image description here

Update: this behaviour appears on Windows 10 when running either IE 11 or Edge and only the second time a file is being opened. It happens for both .pdf and .docx files.

4

3 回答 3

1

This is the code I use to stream PDFs to a client. It works in IE 11. The main difference is that I am using BinaryWrite which based on your code, you may not want to do..

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + fileName + ".pdf");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();

There might be a solution here

I'll like this as well just in case..

According to this thread, it could be as simple as replacing Response.Close with Response.End (or in your case.. adding)

于 2016-01-15T13:38:41.167 回答
1

I finally found the answer myself - it had to do with the HTTP header content-length which i mistakenly submitted with a value exactly 1byte too large.

This caused the strange behavior in only IE/Edge and only Windows 10 as described in the OP.

于 2016-04-08T12:40:18.737 回答
0

I had the same problem with an aspx page that transmits file to browser in Page_Load event handler. My mistake was an absense of

Response.End();

method call. When I added this line the problem has gone.

于 2018-11-07T10:34:12.110 回答