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 7062475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:35:54+00:00 2026-05-28T04:35:54+00:00

I am implementing a caching mechanism. I have written a HTTPModule which would intercept

  • 0

I am implementing a caching mechanism. I have written a HTTPModule which would intercept all the response and suffix a buildnumber to the static files. And also rewrite the url in the request by stripping of the build number.

I want to set the MaxAge in the response to a future date, say a year. But when I see it in fiddler it is not setting the max age. I also tried setting the expiry but doesn’t seem to work.

It works fine in IIS 7 integrated mode but not in Classic mode.

 context.Response.Cache.SetCacheability(HttpCacheability.Public);                   
 context.Response.Cache.SetMaxAge(new TimeSpan(DateTime.Now.AddYears(1).Ticks));
 context.Response.Cache.SetExpires(DateTime.Now.AddYears(2));
 context.Response.AddHeader("Expires", DateTime.Now.AddYears(1).ToShortDateString());

None of these seem to make an impact on the cache settings. What is the best way to achieve this ? I don’t want to use Integrated mode.

Update with header information:

HTTP/1.1 200 OK 
Cache-Control: public 
Content-Type: image/gif 
Expires: Fri, 23 Dec 2011 14:53:12 GMT 
Last-Modified: Mon, 21 Nov 2011 11:50:11 GMT 
Accept-Ranges: bytes 
ETag: "1CCA843B92E5B80" 
Server: Microsoft-IIS/7.5 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Thu, 22 Dec 2011 14:53:12

The response headers when the cache control set to private

HTTP/1.1 200 OK
Cache-Control: private, max-age=31536000
Content-Length: 2157
Content-Type: text/css
Expires: Sat, 24 Dec 2011 09:03:41 GMT
Last-Modified: Mon, 21 Nov 2011 11:50:09 GMT
Accept-Ranges: bytes
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 23 Dec 2011 09:03:41 GMT

I have included the code which I am using

  context.BeginRequest += new EventHandler(this.AddCacheExpiry);

  private void AddCacheExpiry(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;           

        if (context.Request.AppRelativeCurrentExecutionFilePath.IndexOf(BuildNumber) != -1)
        {
                context.Response.Cache.SetCacheability(HttpCacheability.Private);                   
                context.Response.Cache.SetMaxAge(new TimeSpan(DateTime.Now.AddYears(1).Ticks));
                context.Response.Cache.SetExpires(DateTime.Now.AddYears(2));
                context.Response.Cache.SetLastModifiedFromFileDependencies(); 
        }
    }
  • 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-28T04:35:55+00:00Added an answer on May 28, 2026 at 4:35 am

    I ran into the same problem on Win2k8 IIS7. My resolution was to ensure that I commented out caching references in the system.webServer section of web.config:

    <!--<caching>
      <profiles>
        <add extension=".ico" kernelCachePolicy="CacheUntilChange" />
        <add extension=".css" kernelCachePolicy="CacheUntilChange" />
        <add extension=".gif" kernelCachePolicy="CacheUntilChange" />
        <add extension=".js" kernelCachePolicy="CacheUntilChange" />
      </profiles>
    </caching>-->
    
    <staticContent>
      <!--<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />-->
    </staticContent>
    

    Also make sure you have no <%@ OutputCache %> directives on the Page handler if you are using one, and that you are not overriding the cache with Response.Expires etc.

    Output caching will always override your Response.Cache settings it seems.

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

Sidebar

Related Questions

I'm implementing a PHP script which will need some caching capabilities. I'm trying to
So I have a class which overrides Equals(object obj) and GetHashCode() along with implementing
I'm on my way with implementing a caching mechanism for my Android application. I
I have a wcf service that is secured using WIF. I'm implementing token caching
I am implementing caching for my Python application and I want to use memcached.
We are looking at implementing a caching framework for our application to help improve
I've created a forum, and we're implementing an apc and memcache caching solution to
When implementing Quicksort, one of the things you have to do is to choose
I'm implementing an image cache system for caching downloaded image. My strategy is based
We are implementing a system that analyses books. The system is written in PHP,

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.