2016-01-15 70 views
0

我有一個用戶報告說文件在瀏覽器中顯示爲原始數據。他使用Internet Explorer。PDF文件有時顯示爲垃圾

這些文件通過.ashx處理程序文件進行處理,它一直在工作。

這是我的ashx的處理程序的相關部分:

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() 

任何人都可以想辦法的這個畫面嗎? enter image description here

更新:當運行IE 11或Edge並且僅在第二次打開文件時,此行爲出現在Windows 10上。它發生在.pdf和.docx文件中。

回答

1

我終於找到了答案 - 它必須與HTTP hea der content-length,我錯誤地提交了一個正好1byte太大的值。

這會導致在IE/Edge中出現奇怪的行爲,並且僅在OP中描述了Windows 10。

1

這是我用來將PDF流式傳輸到客戶端的代碼。它工作在IE 11的主要區別是,我使用了基於代碼的BinaryWrite,你可能不希望做..

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..

this thread,它可以像替換Response.CloseResponse.End(或在你的情況下..添加)一樣簡單