我的情況是這樣的:從服務器返回PDF
我讀,並從服務器中,然後在iframe
內顯示返回一個PDF文件。以下代碼適用於IE。但是,當我通過Chrome訪問該網站時,我收到了所有垃圾字符。
while ((byteCount = inStr.Read(buffer, 0, buffer.Length)) > 0)
{
if (HttpContext.Response.IsClientConnected)
{
HttpContext.Response.BufferOutput = true;
HttpContext.Response.ContentType = "application/pdf";
HttpContext.Response.OutputStream.Write(buffer, 0, buffer.Length);
//HttpContext.Response.Flush();
}
}
當我刷新響應,我確實看到PDF正確。問題在於調用flush會導致服務器上的"Server cannot set status after HTTP headers have been sent"
警告。
問題是:爲什麼Chrome需要刷新,並且如果有避免刷新的方法?到目前爲止,我已閱讀所有帖子,無法解決與刷新相關的服務器錯誤。
服務器 - IIS7,在Windows Server 2008 R2
應用程序 - ASP.Net 4.0.30319.0,C#,阿賈克斯
而沒有使用返回'FileResult'動作? – codingbiz
直接發送到iFrame的pdf文件顯示在fancybox內。不確定在這種情況下是否返回FileResultwill工作。 – user1135625