Web api 下载xls 遇到was not able to open this internet site.

调用http://localhost:2000/api/v1.0/Report/1

发现第一次不成功,刷新后可以。

加入红色代码即可。

出现这个问题的还有其他原因这个不一定可以解决。

HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

result.Headers.Clear();

result.Content = new ByteArrayContent(data);

result.Content.Headers.Add("Content-Disposition", "attachment; filename=report.xls");

  result.Headers.CacheControl = new CacheControlHeaderValue() { NoCache = false,  NoStore = false};

  result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");

 

原因:

要使 Internet Explorer 能够在 Office(或任何进程外 ActiveX 文档服务器)中打开文档,Internet Explorer 必须将文件保存到本地缓存目录中,并要求相关联的应用程序通过使用 IPersistFile::Load 加载该文件。如果该文件未存储在磁盘中,此操作将失败。

 

当 Internet Explorer 通过 SSL 与安全 Web 站点通信时,它会强制执行任何 no-cache 请求。如果存在标头,Internet Explorer 将不缓存该文件。因此,Office 无法打开该文件。

 

http://support.microsoft.com/kb/316431/zh-cn

posted @ 2014-03-26 13:40  游子看世界  阅读(266)  评论(0)    收藏  举报