Asp.Net MVC 4 API: Download of docx failing in IE8
asp.net-mvc-4, c#
Solution
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.
Not really nice, but it seems that the MVC 4 API brings some restrictions with it.
Problem
I'm storing documents in a database and have an api for downloading documents. 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: Unable to download 393 from idler2. Unable to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. 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 ``` This is my api method: ``` 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..