2016-04-14 118 views
1

我正在使用C#ASP.NET Web應用程序。我們創建了一個超鏈接來打開PDF文檔。 PDF文檔需要在瀏覽器中內聯打開。在桌面上的Chrome上,它工作正常。在Android上的Chrome上,它下載PDF文件。我該如何解決這個問題,以便它可以在兩臺設備上以內聯方式打開PDF?如何在chrome android上強制打開pdf文檔內聯?

這是我的代碼:

var document = sessionManager.DocumentServiceClient.GetDocument(documentId, documentStorageType); 

this.Response.Clear(); 
this.Response.ContentType = "application/pdf"; 
this.Response.AddHeader("Content-Disposition", string.Format("inline; filename = \"{0}.pdf\"", this.DocumentTitle)); 
this.Response.OutputStream.Write(document.FileData, 0, document.FileData.Length); 
this.Response.End(); 
+0

可能的複製[如何通過Android網頁瀏覽器顯示PDF而無需首先下載](http://stackoverflow.com/questions/7437602/how-to-display-a-pdf-via -android-web-browser-without-download-first) – JimmyB

+0

有沒有解決辦法,我想我的問題是不一樣的。 – Jax

回答

0

此修復程序是使用的contentType:

this.Response.ContentType = "application/octet-stream"; 

它也需要刪除的文件名空間:

this.Response.AddHeader("Content-Disposition", string.Format("inline; filename = \"{0}.pdf\"", this.DocumentTitle.Replace(" ","")));