Returning PDF from ASP.NET Web API crashes IE -


i'm using httpresponsemessage display files through web api. if use content disposition type attachment have no problems. i've been asked have them open directly in browser (disposition type attachment). changed type inline , works fine in every browser except ie. "internet explorer has encountered error , needs close" error when try use ie.

here's code i'm using

httpresponsemessage response = new httpresponsemessage(httpstatuscode.ok);         byte[] filebytes = null;                  using (filestream fs = new filestream(strpath, filemode.openorcreate, fileaccess.readwrite))                 {                     filebytes = new byte[fs.length];                     fs.read(filebytes, 0, filebytes.length);                 }             response.headers.clear();             response.content = new bytearraycontent(filebytes);             cachecontrolheadervalue cch = new cachecontrolheadervalue();             cch.private = true;             response.headers.cachecontrol = cch;             response.content.headers.contenttype = new system.net.http.headers.mediatypeheadervalue("application/pdf");             response.content.headers.contentlength = filebytes.length;             contentdispositionheadervalue ch = new contentdispositionheadervalue("attachment");             ch.filename = "document.pdf";             response.content.headers.contentdisposition = ch;           return response; 

what i've tried:

  • adding date created headers
  • using stream instead of byte array
  • removing private cache control header. added because of issue having windows xp machines not displaying files. when remove cache control header still have issue. not problem.
  • clearing out headers first, , not clearing out headers first

any suggestions?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -