Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7168643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:49:15+00:00 2026-05-28T14:49:15+00:00

I’m working on a web app in ASP.NET 2.0 that involves serving images via

  • 0

I’m working on a web app in ASP.NET 2.0 that involves serving images via a resource handler (.ashx). I’ve just implemented handling cache headers and conditional GET requests, so that I don’t have to serve all the images for every request. But I’m not sure I’m completely understanding what’s happening with the browser’s cache.

Images are fetched via urls like http://www.mysite.com/image.ashx?imageID=3. My code in the handler looks something like this:

int imageID = -1;
try
{
  imageID = Int32.Parse(context.Request["imageID"]);
}
catch (Exception) {}

MyImageClass image = DataLayer.GetImage(imageID);
if (image != null)
{
  DateTime requestedDate = DateTime.MinValue;
  if (context.Request.Headers["If-Modified-Since"] != null)
  {
    requestedDate = DateTime.Parse(context.Request.Headers["If-Modified-Since"])
      .ToLocalTime();
  }

  if (requestedDate < image.ModifiedDate)
  {
     context.Response.AddHeader("content-type", image.ContentType);
     context.Response.CacheControl = HttpCacheability.Private.ToString();
     context.Response.Cache.SetLastModified(image.ModifiedDate.ToUniversalTime());
     context.Response.Cache.SetMaxAge(TimeSpan.FromDays(1));
     //write image to output stream
  }
  else
  {
    context.Response.StatusDescription = "Not Modified";
    context.Response.StatusCode = 304;
  }
}

This is what the response header looks like the first time an image is requested:

HTTP/1.1 200 OK
Cache-Control: private, max-age=86400
Content-Length: 1048576
Content-Type: image/jpeg
Expires: Sat, 28 Jan 2012 17:17:11 GMT
Last-Modified: Fri, 27 Jan 2012 16:50:27 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 27 Jan 2012 17:17:10 GMT

And this is a response to a subsequent request:

HTTP/1.1 304 Not Modified
Cache-Control: private
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Fri, 27 Jan 2012 17:17:30 GMT
Connection: close

Watching the requests in Fiddler, I’m noticing that the browser (Firefox 9) always makes a conditional GET request for the image after the first request. It gets the 304 Not Modified response and pulls the image from cache, which is great. But isn’t there a way to make it always pull from the cache, without even asking the server, until after the header’s max-age (or expiry date) is past? I’ve tried using context.Response.Cache.SetExpires() with a future date, and the browser still makes the conditional GET request.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:49:16+00:00Added an answer on May 28, 2026 at 2:49 pm

    When you press F5 or Reload, Firefox will always send conditional requests.

    If you navigate to the page normally (eg, clicking a link or using the address bar), it will go straight to the cache.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.