locked
Thumbnail refresh RRS feed

  • Question

  • User2006713638 posted

    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();
    Monday, February 13, 2012 4:09 PM

Answers

  • User-718146471 posted

    To get access to it, you have to do something like HTTPContext.Current or something like that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 14, 2012 7:42 AM

All replies

  • User-718146471 posted

    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.

    Monday, February 13, 2012 4:22 PM
  • User2006713638 posted

    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".

    Monday, February 13, 2012 6:54 PM
  • User-718146471 posted

    To get access to it, you have to do something like HTTPContext.Current or something like that.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 14, 2012 7:42 AM