Images not caching in browser

Last post 06-09-2009 6:18 AM by sumitd. 6 replies.

Sort Posts:

  • Images not caching in browser

    11-24-2005, 1:58 PM
    • Member
      40 point Member
    • damiensawyer
    • Member since 07-26-2004, 2:16 AM
    • Posts 10
    Hello all,

    I've just gone live with my first csk. I'm a relative newbie to the ASP world and am having some issues.

    For reasons unknown to me, the images in the site (stored in SQL) are not caching in the browser. Every time the use goes to another page in the site, the header banner reloads. Whilst this is acceptible for broadband users, it almost makes the site unusable via slow connections.

    To see what I mean, you can check out the site at htttp://www.callofguadalupe.org

    Does anyone have any ideas?

    Thanks very much in advance.



    Damien Sawyer
  • Re: Images not caching in browser

    11-24-2005, 3:16 PM
    • Contributor
      4,482 point Contributor
    • jodywbcb
    • Member since 03-12-2003, 3:52 PM
    • West Seattle,WA
    • Posts 985
    It could be that it is because you have the images saved with what is called progressive rendering.  Not sure though. 

    However you could do a fix to it if you like:


    Anywhere nywhere you see this in your ImageUtility:

                Context.Response.ContentType = contentType.ToLower();

                return image;


    Insert in between those lines the following:

                Context.Response.Cache.SetCacheability(HttpCacheability.Public);
                Context.Response.BufferOutput = false;

    Would like so:

                Context.Response.ContentType = contentType.ToLower();
                Context.Response.Cache.SetCacheability(HttpCacheability.Public);
                Context.Response.BufferOutput = false;
                return image;


    You will find those methods in both the ImageHandler.cs and ImageUtility.cs.  You need to make sure however you are only adding that for the methods that actually stream back the image to the client not for the image manipulation or save routine.

    It may or may not resolve your issue. 

    -- jody
    My Blogs on .Net 2.0 and Ajax
    http://csk.wbcb.com
    http://ArtbyJody.com
  • Re: Images not caching in browser

    11-25-2005, 9:15 PM
    • Member
      40 point Member
    • damiensawyer
    • Member since 07-26-2004, 2:16 AM
    • Posts 10

    Hi Jody,

    Thanks very much for your suggestion. Unfortunately, it didn't solve the problem. It did however show something suspicious. I don't have 

    Context.Response.ContentType = contentType.ToLower();
    or
    return image;


    anyway in my code!

    I have included the DisplayCommunityImage method from ImageHandler.cs (including my modifications per your suggestion). Is it possible that I am running a different/older version of the CSK? The csproj file in my solution is named "CommunityStarterKitCSVS_v1_0.csproj". Is there a later version than 1_0?

    private void DisplayCommunityImage(HttpContext context, string fileName) {

    SqlDataReader dr;

    dr = ImageUtility.GetCommunityImage(fileName);

    if(dr.Read()) {

    SqlBinary buffer= (byte[])dr["Image_imageData"];

    context.Response.ContentType = dr["Image_contenttype"].ToString();

    // Start Damien's Changes

    context.Response.Cache.SetCacheability(HttpCacheability.Public);

    context.Response.BufferOutput = false;

    // End Damien's Changes
    context.Response.BinaryWrite((byte[])buffer );

    }

    }


    I haven't really made any siginificant mods to the base application (only theme's changes), so, short of me using an older versioin, I don't know why I would be having this issue when others aren't.

    Any ideas?

    Thanks very much for your support.

    Damien



    PS - I checked out your art site Jody, very impressive!

  • Re: Images not caching in browser

    11-26-2005, 12:22 AM
    • Contributor
      4,482 point Contributor
    • jodywbcb
    • Member since 03-12-2003, 3:52 PM
    • West Seattle,WA
    • Posts 985
    To be honest I have no idea about the versions and what they display.  I would recommend migrating to the GCN version available on both http://reddnet.com and http://csk.wbcb.com.  And see if that fixes your issue.   You might also try saving your image as non-progressive.  There may be an issue with the binary write when images are saved with progressive.  Progressive is a mode that when an Image is saved with it (jpegs) then it does a level by level pass when displaying.  Since the image in question is your logo - (it appeared the other image seemed to be cached)...  I would see if that is causing the problem.  There is a setting in IIS to that handles streaming of images but for the life of me I foregt what it is which also forces IIS to stream images differently...

    Thanks for the compliments btw - much appreciated!


    -- jody
    My Blogs on .Net 2.0 and Ajax
    http://csk.wbcb.com
    http://ArtbyJody.com
  • Re: Images not caching in browser

    11-26-2005, 4:07 AM
    • Member
      40 point Member
    • damiensawyer
    • Member since 07-26-2004, 2:16 AM
    • Posts 10
    Hi again,

    Thanks for the suggestion. I tried saving the files without the progressive thing, however it was to no avail. Oh well.

    I think that i'm going to give up on it for now.

    Thanks very much for your help.



    Damien
  • Re: Images not caching in browser

    06-09-2009, 6:05 AM
    • Member
      18 point Member
    • Saurabh7820
    • Member since 06-09-2009, 10:03 AM
    • Posts 4

     Hope this will help you.

    http://www.codeproject.com/KB/aspnet/CachingImagesInASPNET.aspx

  • Re: Images not caching in browser

    06-09-2009, 6:18 AM
    • Star
      10,646 point Star
    • sumitd
    • Member since 07-16-2008, 12:32 PM
    • Bangalore
    • Posts 1,872

     Put below lines on Page_Load:

    Response.Cache.SetCacheability(HttpCacheability.Public)

     

    Please mark it as answer if it resolves the issue.

    visit: http://technicalsol.blogspot.com

    Latest ajax control toolkit (Release: May 13, 2009): http://ajaxcontroltoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27326
Page 1 of 1 (7 items)