0

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.

kozmi
  • 25
  • 2
  • 8
  • 1
    If a tree doesn't have the ability to grow money, simply telling it to won't make it grow money. As far as I know the ability to open the PDF in the browser relies on the browser having this capability. – The Muffin Man Jan 28 '13 at 22:41
  • interesting point nick. But, I know in my case all my browsers display pdf's. Is it a plug-in per browser issue? (i know you're implying it is, but plz confirm thats what you mean. – Dave Alperovich Jan 28 '13 at 23:14
  • This is what he's saying. Chrome has a built in pdf reader. The other browsers do not. – Chad Ruppert Jan 29 '13 at 00:03
  • Touche! (PS. Trees=>paper=>money *ahem*) – kozmi Jan 29 '13 at 17:33

1 Answers1

-1

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

VahidN
  • 18,457
  • 8
  • 73
  • 117
  • Controller.Redirect() takes a string URL to redirect the user. I'm failing to see how this is relevant in displaying a file. Please explain. – kozmi Jan 29 '13 at 17:02
  • Test it. Redirect the user to the location of that pdf file. Now all of the browsers know how to display it instead of showing the save popup dialog. – VahidN Jan 29 '13 at 18:15