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

  • Home
  • SEARCH
  • 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 8168439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:31:33+00:00 2026-06-06T20:31:33+00:00

In our Asp.Net Application we have an IHttpHandler handling requests for Images. The Handler

  • 0

In our Asp.Net Application we have an IHttpHandler handling requests for Images.
The Handler is called with a special id which identifies an image in our Image Cache.
Once an image is put into the cash it never changes.
My question is:

Is it okay to always return the http status code 304 for requests with a “If-Modified-Since” header without actually checking the given date?
The reasoning is that the browser must already have a copy of the image (since it provided the modified-since header).

This would make life easier, because we do not (yet) track the image creation date.

Here is the actual code (Update: I included the if-modified header now in the server response as recommended by Aristos):

public void ProcessRequest(HttpContext context)
{
    if (!String.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"])) {
        //Is this okay?
        context.Response.StatusCode = 304;
        context.Response.StatusDescription = "Not Modified";
        return;
    }
    var thumbnailId = context.Request.QueryString["thumbnail"];
    using (var thumbnailCache = new CThumbnailCache()) {
        var imageBytes = thumbnailCache.GetImageById(thumbnailId);

        context.Response.ContentType = "image/png";
        var outputStream = context.Response.OutputStream;
        outputStream.Write(imageBytes, 0, imageBytes.Count());
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.Cache.SetLastModified(DateTime.UtcNow);
        // added after Aristos post
        context.Response.AddHeader("If-Modified-Since", DateTime.UtcNow.ToString("r"));

        const int maxAge = 86400 * 14; // 14 Tage
        context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(maxAge));
        context.Response.Cache.SetMaxAge(new TimeSpan(0, 0, maxAge));
        context.Response.CacheControl = "private";
        context.Response.Cache.SetValidUntilExpires(true);

    }
}
  • 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-06-06T20:31:35+00:00Added an answer on June 6, 2026 at 8:31 pm

    its ok, from the moment you get the If-Modified-Since the resource is on browser and you decide if you let it be as it is.

    I like here to say you two thinks. You do not seems that you set this header so you probably not get it by the browser.

    To make this actual works you need to add this line

    context.Response.AddHeader("If-Modified-Since", LastModifledOfImage.ToString()); 
    

    or as you do send the current date-time:

    context.Response.AddHeader("If-Modified-Since", DateTime.UtcNow.ToString());
    

    when you send the image.
    I see that you use the SetLastModified but this is set the Last-Modified header not the one you check.

    Consider to make actually static this images if possible because even this If-Modified-Since make one call to the server, but the actually static resource gets the image direct from the browser cache with out asking the server.

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

Sidebar

Related Questions

We have an ASMX web service which we invoke from our ASP.NET application using
I have a Generic HTTP Handler (*.ashx) in my ASP.Net application which performs some
We have a global error handler in our ASP.NET application that logs and emails
I have a location using our ASP.NET 4.0 web application which was running fine
We currently have fairly robust error handling functionality in our ASP.Net application. We log
We are considering using Cassette in our asp.net web application which might be accessed
I have an ASP.NET 2.0 application that is working fine in our local environment.
In our ASP.NET MVC application, we've noticed that we cannot have The Forbidden DOS
In our current Asp.net MVC application we have 2 menu systems one accross the
I have implemented URL mapping in our ASP.NET 4 application, but I have a

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.