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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:44:50+00:00 2026-06-11T08:44:50+00:00

It seems as if, once you set the cacheability on Response.Cache to NoCache ,

  • 0

It seems as if, once you set the cacheability on Response.Cache to NoCache, there’s no way to change it again. Here is a simple but complete illustration of the issue:

protected void Page_Load(object sender, EventArgs e)
{
    FieldInfo fi = typeof(HttpCachePolicy).GetField(
        "_cacheability",
        BindingFlags.NonPublic | BindingFlags.Instance);

    // Default value = 6
    HttpCacheability first = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can change it to Public
    Response.Cache.SetCacheability(HttpCacheability.Public);
    HttpCacheability second = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can change it to Private
    Response.Cache.SetCacheability(HttpCacheability.Private);
    HttpCacheability third = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can change it to NoCache
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpCacheability fourth = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can't go back to Private!  Stuck on NoCache
    Response.Cache.SetCacheability(HttpCacheability.Private);
    HttpCacheability fifth = (HttpCacheability)fi.GetValue(Response.Cache);
}

Am I missing something? Is there a way to do this?

EDIT: Of course, it works if I set it with Reflection, but I’m worried that there’s something else happening when you set to HttpCacheability.NoCache that I would miss if I went behind the scenes.. and would prefer to do it in an officially-supported way anyway.

EDIT2: Same thing seems to happen with Private; can you only go more restrictive?

protected void Page_Load(object sender, EventArgs e)
{
    FieldInfo fi = typeof(HttpCachePolicy).GetField(
        "_cacheability",
        BindingFlags.NonPublic | BindingFlags.Instance);

    // Default value = 6
    HttpCacheability first = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can change it to Private
    Response.Cache.SetCacheability(HttpCacheability.Private);
    HttpCacheability second = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can't change to Public!  Stuck on Private
    Response.Cache.SetCacheability(HttpCacheability.Public);
    HttpCacheability third = (HttpCacheability)fi.GetValue(Response.Cache);

    // Can change to NoCache - Can only go more restrictive?
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpCacheability fourth = (HttpCacheability)fi.GetValue(Response.Cache);
}
  • 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-11T08:44:51+00:00Added an answer on June 11, 2026 at 8:44 am

    Cracked open Reflector and took a look inside HttpCachePolicy:

    public void SetCacheability(HttpCacheability cacheability)
    {
        if ((cacheability < HttpCacheability.NoCache) || (HttpCacheability.ServerAndPrivate < cacheability))
        {
            throw new ArgumentOutOfRangeException("cacheability");
        }
        if (s_cacheabilityValues[(int) cacheability] < s_cacheabilityValues[(int) this._cacheability])
        {
            this.Dirtied();
            this._cacheability = cacheability;
        }
    }
    

    s_cacheabilityValues is set during the static constructor:

    s_cacheabilityValues = new int[] { -1, 0, 2, 1, 4, 3, 100 };
    

    Dirtied() is called, but it just seems to set some flags:

    private void Dirtied()
    {
        this._isModified = true;
        this._useCachedHeaders = false;
    }
    

    It does look ilke there are rules for changing the values, but there doesn’t look like they have much effect. As such, probably safe to just change using reflection.

    fi.SetValue(Response.Cache, HttpCacheability.Private);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems a simple thing but i'm unable to solve it and i really
My problem seems to be really simple but I just can't get the reason
It seems that this should be a simple thing but I can't figure it
I've set up Google Analytics and three goals. But it seems like each goal
Seems like a simple issue but I'm obviously missing something. I have a ViewBag
It seems that once an Ocean Workstep derivative class has been released to production
Seems to be a problem that many people have, but all the answers I
Seems that This will be an easy question for you but this problem is
Seems, it's common task, but I haven't found solution. I need to calculate number
Seems like there should be... Right now it just seems like magic that you

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.