Asp.net Response.write PDF to IE browser and got garbled

Asp.net response.write a binary pdf file to chrome is ok , but ie is fail that got garbled. Because ie must get server response a end tag.

在 Asp.net 寫出 PDF 檔至前端瀏覽器顯示。在 chrome 可以正常顯示,但在 IE 上無法檢視 僅出現亂碼。因為 IE 會跟你計較輸出資料串流時有沒有告知它串流已輸出完了。Response.End() 沒給 IE 就出亂碼。

程式片段

myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();

if (myReader.Read())
{
//Response.ContentType = myReader[“MIME"].ToString();
Response.ContentType = “application/pdf";
Response.BinaryWrite((byte[])myReader[“isoebb010″]);
Response.End();
}
else{
Response.Write(“你沒有權限瀏覽與列印所選取的文件。
如有任何疑問請聯繫資訊課人員。");
}

myReader.Close();
myConnection.Close();
[/sourcecode]

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s