2012-04-13 130 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