c# - Internet Explorer not properly downloading image from WCF -


i have wcf service provides endpoint dynamically generate qr-code image. image first written memory stream tempstream. have following code in endpoint:

httpresponse response = httpcontext.current.response; response.clear(); response.clearcontent(); response.clearheaders();  response.buffer = false; response.contenttype = "image/png"; response.cachecontrol = "no-cache";  response.addheader("content-length", tempstream.length.tostring()) response.addheader("accept-ranges", "bytes");  tempstream.writeto(response.outputstream);  response.flush(); response.end(); 

it works fine in firefox. image downloaded if hit endpoint manually , loads inline if reference endpoint src attribute in img tag. however, in ie, image not load inline in img tag, , if try hit endpoint manually, loads full image first time subsequent refreshes (seemingly until browser restarted), loads part of image.

upon inspection of network tab in f12 window, seems downloading 1.00 kb of data (including headers) server, meaning gets 750 kb of image data. makes identical request server , gets headers no image data. content-length header set correctly size of image; ie doesn't download much. again, firefox fine.

my coworker recommended set transfermode streamed in web.config, did, didn't work either. how can ie download entire image in 1 go?

edit:

i should note when running wcf service in visual studio's iis express server, internet explorer works fine. when application deployed iis 7.5 problem occurs. firefox works fine in both environments.

edit 2:

i added thread.sleep(1000) response, right before response.end(), , fixed issue. ie downloads entire response , not attempt make second request. why?! response.flush(); should block request , emit all data client before response.end() called, , far know, response.end() flushes stream calling flush() manually redundant. why blocking thread explicitly 1 second make work? should note if don't put thread.sleep(1000) in, still works first request because .net has jit-compile backend each time apppool restarted, blocks request amount of time, thread.sleep(1000) does.

try this:

response.addheader("content-disposition", "filename=" + filename); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -