c# - how to display image directly from httpwebresponse stream in asp.net? -


i want display image recieved webresponse browser directly without saving file.i have used below code save image file want display in browser directly.the website provides captcha image in webresponse want display.please me.

public void captcha(string id, string pass) {     httpwebrequest req;     httpwebresponse response;     string strnewvalue,ckuser,ckpass;     system.drawing.image returnval;     ckuser = id;     ckpass = pass;     this.req = (httpwebrequest)webrequest.create("http://site2sms.com/security/captcha.asp");     servicepointmanager.expect100continue = false;     this.req.cookiecontainer = new cookiecontainer();     this.req.allowautoredirect = false;     this.req.useragent = "mozilla/5.0 (windows nt 6.1; rv:8.0) gecko/20100101 firefox/8.0";     this.req.accept = "*/*";     this.req.method = "post";     this.req.cookiecontainer = cookiecntr;     this.req.contenttype = "application/x-www-form-urlencoded";     this.req.referer = "http://site2sms.com/verification.asp?source=login";     this.strnewvalue = "user=" + ckuser + "&password=" + ckpass + "&submit=sign+in";     this.req.contentlength = this.strnewvalue.length;     streamwriter writer = new streamwriter(this.req.getrequeststream(), encoding.ascii);     writer.write(this.strnewvalue);     writer.close();     this.response = (httpwebresponse)this.req.getresponse();     returnval = image.fromstream(response.getresponsestream());    // returnval.save( server.mappath("captcha.bmp"));     response.appendheader("content-disposition:", "inline;filename=captcha.bmp");     response.contenttype = "image/bmp";     response.write(returnval);     response.end();     this.response.close();  } 

  • you can use httpresponse.writefile method send stream client directly. writes specified file directly http response output stream.

  • you can create ihttphandler send stream, avoid page life circle, increase performance. here link


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -