我有一個ASP.Net網站在回傳到初始頁面之後流回PDF文檔。在IE,Chrome,Firefox以及iPhone和iPad上,一切正常,PDF發送到瀏覽器。在Android手機上,我收到錯誤消息,指出PDF無效。下面的代碼是我試圖做的簡化版本,但它確實重現了錯誤。我基本上有一個設置在服務器上運行的網頁上的按鈕。在頁面的第一個請求時,它會顯示HTML和按鈕點擊之後,它應該呈現的PDF:Android手機未在ASP.Net網站發佈回傳後流式傳輸PDF網站
protected void Page_Load(object sender, EventArgs e)
{
Response.ClearHeaders();
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
Response.AppendHeader("Expires", "0"); // HTTP 1.1
if (IsPostBack)
{
Response.ClearContent();
Response.ClearHeaders();
string fullPath = @"C:\Temp\outdoc.pdf";
if (System.IO.File.Exists(fullPath))
{
//Set the appropriate ContentType.
Response.ContentType = "application/pdf";
//Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=\"TestDoc.pdf\"");
byte[] b = System.IO.File.ReadAllBytes(fullPath);
this.Page.Response.AddHeader("Content-Length", b.Length.ToString());
//Write the file directly to the HTTP content output stream.
Response.BinaryWrite(b);
Response.Flush();
Response.End();
Response.Close();
}
}
}
我已經打了很多在頭不同的價值觀和關閉不同的方式和沖洗響應流沒有運氣。有沒有人看過這個或任何人都可以提供任何建議的事情來嘗試。
編輯:我發現這隻發生在我回發頁面時。如果我只是將文檔直接從文件中傳出,文檔就可以正確傳輸。這導致我相信這是Android瀏覽器的某種緩存問題。 謝謝。
謝謝。我會給這個鏡頭,讓你知道。 –