2012-04-13 128 views
1

我有返回PDF文件的MVC應用程序。IE8無法下載pdf文件

public FileStreamResult GetDocument(int id) 
{ 
    return File(stream, "application/octet-stream", documentsModel.Name); 
} 

我有兩個測試服務器。一個是私人的,另一個是公共的。

私人我可以下載文件,我也得到:

GET /Documents/GetDocument/3576 HTTP/1.1 
Accept: */* 
Accept-Language: en-GB 
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BRI/2) 
Accept-Encoding: gzip, deflate 
Host: appserver 
Connection: Keep-Alive 
Cookie: ASP.NET_SessionId=vgzn4qkelxdmic3nbaqftsxd; .FidesAuthCookie=BF08E0DCAAA54D7D78AB6BD30D5ECA523C045F9B401B10693B6CE57D7D4C677C0908E24D92511DC75A487D6CAE6DD780AA8B4419A5A5D9258A4985AF6870D3AD1A0B3C01B8A620A1E14FEDDE298CCE255AE4B4C2F76D2635B8C5DF332AF19AAB; dynatree-active=3576; dynatree-focus=; dynatree-expand=496%2C603%2Cfolder_622; dynatree-select= 


HTTP/1.1 200 OK 
**Cache-Control: private, s-maxage=0** 
Content-Type: application/octet-stream 
Server: Microsoft-IIS/7.5 
Set-Cookie: .FidesAuthCookie=BF08E0DCAAA54D7D78AB6BD30D5ECA523C045F9B401B10693B6CE57D7D4C677C0908E24D92511DC75A487D6CAE6DD780AA8B4419A5A5D9258A4985AF6870D3AD1A0B3C01B8A620A1E14FEDDE298CCE255AE4B4C2F76D2635B8C5DF332AF19AAB; expires=Fri, 13-Apr-2012 13:31:05 GMT; path=/ 
X-AspNetMvc-Version: 3.0 
Content-Disposition: attachment; filename=test.pdf 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Fri, 13 Apr 2012 13:01:04 GMT 
Content-Length: 49613 

從我的公共服務器,我得到

GET /Documents/GetDocument/97 HTTP/1.1 
Accept: */* 
Accept-Language: en-GB 
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; BRI/2) 
Accept-Encoding: gzip, deflate 
Host: beta.qi-care.nl 
Connection: Keep-Alive 
Cookie: ASP.NET_SessionId=h3utp0bfu4zwhqysntame3we; dynatree-active=97; dynatree-focus=; dynatree-expand=4%2Cfolder_10; dynatree-select=; .FidesAuthCookie=F0DED3D98BF4115C910B0A29EC2C809902B49F15518952DFA78DDB4358B5F0C1A9EDAFB50DD0CA761B433ED68034C2539ABCCDA0C50FF5EEEE3573D3C77E550416CDB24B302C9EB831AC597040E6D255E9B582E8A29D5FC03454F2A0742ECC9DEC61070091F9A66D1C3FC7F9CA10C1B8BB9B5109CB613C98AEE32AFE5A0F8A28 



HTTP/1.1 200 OK 
**Cache-Control: private, no-cache="Set-Cookie", s-maxage=0** 
Content-Type: application/octet-stream 
Server: Microsoft-IIS/7.5 
Set-Cookie: .FidesAuthCookie=F0DED3D98BF4115C910B0A29EC2C809902B49F15518952DFA78DDB4358B5F0C1A9EDAFB50DD0CA761B433ED68034C2539ABCCDA0C50FF5EEEE3573D3C77E550416CDB24B302C9EB831AC597040E6D255E9B582E8A29D5FC03454F2A0742ECC9DEC61070091F9A66D1C3FC7F9CA10C1B8BB9B5109CB613C98AEE32AFE5A0F8A28; expires=Fri, 13-Apr-2012 13:19:35 GMT; path=/ 
X-AspNetMvc-Version: 3.0 
Content-Disposition: attachment; filename=test.pdf 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Fri, 13 Apr 2012 12:49:35 GMT 
Content-Length: 49613 

,我得到錯誤

http://support.microsoft.com/kb/323308

出於某種原因,我從這兩臺服務器獲得了兩個不同的響應。但是,我在微軟的支持發現,客戶應該更改註冊表

To resolve this issue in Internet Explorer 7 and in Internet Explorer 8, follow these steps: 
Start Registry Editor. 
For a per-user setting, locate the following registry key: 
    HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings 
For a per-computer setting, locate the following registry key: 
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings 
On the Edit menu, click Add Value. 
To override the directive for HTTPS connections, add the following registry value: 
    "BypassSSLNoCacheCheck"=Dword:00000001 
To override the directive for HTTP connections, add the following registry value: 
    "BypassHTTPNoCacheCheck"=Dword:00000001 
Quit Registry Editor. 

Microsoft

回答

0

我們面臨的工作這個問題,原來是在Internet Explorer中的錯誤(在我們的例子IE8-),讓嘗試使用SSL下載文件時出錯(您是否在https中,對不對?)。問題是,如果服務器向瀏覽器發送禁用緩存的http標頭,則Explorer會提供錯誤。在你的情況下,maxage=0相當於Cache-Control: no cache

解決方案服務器端是您應該覆蓋此標頭以告知IE8緩存響應,例如Cache-Control: private。 請注意,某些應用程序服務器(例如本例中的Websphere Application Server)會在設置cookie時自動追加no-cache="Set-Cookie"

最後,還有另一種解決方案,如果適用,能解決問題,但應在瀏覽器應用客戶端:

看看方法1: http://support.microsoft.com/kb/2549423