开发者

MVC 3 ContentResult binary file with firefox strange issue

I've got an MVC 3 app that allows users to upload files with some data entry stuff. I've set up a controller that fetches those documents and buffers them out to the user like so

[OutputCache(Duration = 1200, VaryByParam = "id")]
public ContentResult GetNarrative(int id)
{
    Response.Clear();
    Response.BufferOutput = true;
    Response.ContentType = "application/octet-stream";

    var narrative = attachRepo.GetNarrative(id);
    if (narrative == null || narrative.Narrative == null)
        return null;

    Response.AddHeader("Content-Disposition", 
        string.Format("attachment;filename={0}", 
            Server.UrlEncode(narrative.Filename)));

    Response.OutputStream.Write(narrative.Narrative.ToArray(), 
        0, narrative.Narrative.ToArray().Length);
    Response.OutputStream.Flush();
    return Content("");
}

This works fine and well, the interesting thing is that when I have the 开发者_开发知识库output cache line, my firefox download dialog looks like this

MVC 3 ContentResult binary file with firefox strange issue

However when I comment out the output cache line it looks like the expected dialog

MVC 3 ContentResult binary file with firefox strange issue

This isn't really a blocking issue, as it works just fine in IE and Chrome just downloads by default, but I am curious why this would be happening and if anyone has experienced this and worked around it.

Thanks!


I've found that firefox ignores the filename in the Attachment. It tends to use he URL to set the filename.

Try putting at the end of the URL ?filename.docx

And see if it fixes things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜