Asp.Net MVC 4 API:在IE8中的docx失败的下载 [英] Asp.Net MVC 4 API: Download of docx failing in IE8

查看:214
本文介绍了Asp.Net MVC 4 API:在IE8中的docx失败的下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储在数据库中的文件,并具有用于下载文件的API。

I'm storing documents in a database and have an api for downloading documents.

DOCX和XLSX的下载工作在IE9,Chrome和FF罚款,但未能在真正的IE8。(IE 9在IE8模式也适用)

The downloading of docx and xlsx works fine in IE9,Chrome and FF but fails in a real IE8.(IE 9 in IE8 mode also works)

该错误消息我得到的是以下内容:

The error message I get is the following:

无法从idler2下载393。

Unable to download 393 from idler2.

无法打开此Internet站点。该请求的站点
  不可用或不能被发现。请稍后再试。

Unable to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

通过下面的响应头:
HTTP / 1.1 200 OK
缓存控制:无缓存
编译:无缓存

With the following response header: HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache

Content-Length: 10255
Content-Type: application/octet-stream
Expires: -1
Server: Microsoft-IIS/7.5
Content-Disposition: attachment; filename=document.docx
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 23 Mar 2013 11:30:41 GMT

这是我的API方法:

public HttpResponseMessage GetDocumentContent(int id)
{
    Document document = Repository.StorageFor<Client>().GetDocument(id);
    HttpResponseMessage response = Request.CreateResponse(System.Net.HttpStatusCode.OK);
    response.Content = new ByteArrayContent(document.GetBuffer());
    response.Content.Headers.ContentLength = document.GetBuffer().Length;
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    {
        //FileName = document.GetFileName(),
        FileName = "document.docx",
        DispositionType = "attachment"
    };
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");            
    return response;
}

我试过的内容配置和内容的标题相当多的变化,但没有运气..

I've tried quite a few variations on the content disposition and content header, but without luck..

推荐答案

唯一的解决方法,我发现到现在为止是存储在一个临时文件夹中的文件并返回下载网址。然后,(JavaScript)的客户端可以打开一个新窗口。

Only workaround I've found until now is to store the file in a temp folder and return the download url. The (javascript) client can then open a new window.

不是真的不错,但它似乎MVC 4 API给它带来了一些限制。

Not really nice, but it seems that the MVC 4 API brings some restrictions with it.

这篇关于Asp.Net MVC 4 API:在IE8中的docx失败的下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆