Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 14, 2012 11:42 AM by bbcompent1
Member
131 Points
108 Posts
Feb 13, 2012 08:09 PM|LINK
Thumnail image is returned via handler. First time all is OK. but when I do refresh, then istead of image is displayd some machine code in Firefox.
I traced to root cause with Fiddler, it is because first time Content-Type comes correctly image/png
but with refresh it is coming as text/html. what should be added, that after refresh browser still could get image/png? below is my code
Bitmap target = new Bitmap(width, height); context.Response.ContentType = "image/png"; using (Graphics graphics = Graphics.FromImage(target)) { graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingMode = CompositingMode.SourceCopy; graphics.DrawImage(photo, 0, 0, width, height); HttpCachePolicy cachePolicy = context.Response.Cache; cachePolicy.SetCacheability(HttpCacheability.Public); cachePolicy.VaryByParams["car_image_id"] = true; cachePolicy.SetOmitVaryStar(true); cachePolicy.SetExpires(DateTime.Now + TimeSpan.FromDays(365)); cachePolicy.SetValidUntilExpires(true); using (MemoryStream memoryStream = new MemoryStream()) { target.Save(memoryStream, ImageFormat.Png); //cashing using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew)) { memoryStream.WriteTo(diskCacheStream); } memoryStream.WriteTo(context.Response.OutputStream); } context.Response.End(); target.Dispose();
All-Star
33097 Points
8529 Posts
Moderator
Feb 13, 2012 08:22 PM|LINK
I'm thinking you might need to have some of this inside a (!PageIsPostBack) because the second time the pages loads I doubt it is a full postback.
Feb 13, 2012 10:54 PM|LINK
this is HttpHandler and only thing here is "ProcessRequest". I tried adding Postback check, but got error "IsPostback does not exist in the current context".
Feb 14, 2012 11:42 AM|LINK
To get access to it, you have to do something like HTTPContext.Current or something like that.
kvh
Member
131 Points
108 Posts
Thumbnail refresh
Feb 13, 2012 08:09 PM|LINK
Thumnail image is returned via handler. First time all is OK. but when I do refresh, then istead of image is displayd some machine code in Firefox.
I traced to root cause with Fiddler, it is because first time Content-Type comes correctly image/png
but with refresh it is coming as text/html. what should be added, that after refresh browser still could get image/png? below is my code
Bitmap target = new Bitmap(width, height); context.Response.ContentType = "image/png"; using (Graphics graphics = Graphics.FromImage(target)) { graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingMode = CompositingMode.SourceCopy; graphics.DrawImage(photo, 0, 0, width, height); HttpCachePolicy cachePolicy = context.Response.Cache; cachePolicy.SetCacheability(HttpCacheability.Public); cachePolicy.VaryByParams["car_image_id"] = true; cachePolicy.SetOmitVaryStar(true); cachePolicy.SetExpires(DateTime.Now + TimeSpan.FromDays(365)); cachePolicy.SetValidUntilExpires(true); using (MemoryStream memoryStream = new MemoryStream()) { target.Save(memoryStream, ImageFormat.Png); //cashing using (FileStream diskCacheStream = new FileStream(cachePath, FileMode.CreateNew)) { memoryStream.WriteTo(diskCacheStream); } memoryStream.WriteTo(context.Response.OutputStream); } context.Response.End(); target.Dispose();bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Thumbnail refresh
Feb 13, 2012 08:22 PM|LINK
I'm thinking you might need to have some of this inside a (!PageIsPostBack) because the second time the pages loads I doubt it is a full postback.
kvh
Member
131 Points
108 Posts
Re: Thumbnail refresh
Feb 13, 2012 10:54 PM|LINK
this is HttpHandler and only thing here is "ProcessRequest". I tried adding Postback check, but got error "IsPostback does not exist in the current context".
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Thumbnail refresh
Feb 14, 2012 11:42 AM|LINK
To get access to it, you have to do something like HTTPContext.Current or something like that.