Question

I'm running VS 2012 in Windows 8 (on a virtualbox hosted in mac os x). MVC 3 in C#.

When the user selects a Document, it should open in a new browser window.

Currently: Chrome (v24.0.1312.56 m) - opens in new window, as desired
Firefox (v18.0.1) - Prompts user to open or save. Opens in TWinUI (ugh) (and downloads).
IE (v10.0.9200.16466) - Prompts user to open or save. Opens in TWinUI

Here is code:

    [HttpGet]
    public ActionResult Details(int id)
    {
        Document document = portalDB.Documents.Find(id);
        Response.Headers.Remove("Content-Disposition");
        Response.Headers.Add("Content-Disposition", "inline; filename=" + document.FileName);
        return File(System.IO.Path.Combine(Server.MapPath("~/App_Data/Documents"), document.FileName), "application/pdf");
    }

Here is IE Response Header:

Key                     Value
Response                HTTP/1.1 200 OK
Cache-Control           private, s-maxage=0
Content-Type            application/pdf
Server                  Microsoft-IIS/8.0
X-AspNetMvc-Version     3.0
Content-Disposition     inline; filename=DeclarationAndByLaws.pdf
X-AspNet-Version        4.0.30319
X-SourceFiles           =?UTF-8?B?YzpcdXNlcnNcbWlrb1xkb2N1bWVudHNcdmlzdWFsIHN0dWRpbyAyMDEyXFByb2plY3RzXENlZGFyQXBwbGljYXRpb25cQ2VkYXJBcHBsaWNhdGlvblxQb3J0YWxcRGV0YWlsc1wx?=
X-Powered-By            ASP.NET
Date                    Mon, 28 Jan 2013 22:01:52 GMT

Firefox: couldn't get header because firebug didn't persist through download prompt.

Était-ce utile?

La solution

change the return File to return Redirect. return File means flush the file in the browser and end response.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top