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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:04:00+00:00 2026-05-13T15:04:00+00:00

I have some code that is used to replace certain page output with other

  • 0

I have some code that is used to replace certain page output with other text. The way I accomplish this is by setting the Response.Filter to a Stream, Flushing the Response, and then reading that Stream back into a string. From there I can manipulate the string and output the resulting code. You can see the basic code for this over at Render a view as a string .

However, I noticed that Page Caching no longer works after the first Response.Flush call.

I put together a simple ASP.NET WebApp as an example. I have a Default.aspx with an @OutputCache set for 30 seconds. All this does is output DateTime.Now.ToLongTimeString(). I override Render. If I do a Response.Flush (even after the base.Render) the page does not get cached. This is regardless of any programmatic cacheability that I set.

So it seems that Response.Flush completely undermines any page caching in use. Why is this?

extra credit: is there a way to accomplish what I want (render output to a string) that will not result in Page Cache getting bypassed?

ASPX Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCacheVsFlush._Default" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<%= DateTime.Now.ToLongTimeString() %>

Code-behind (Page is Cached):

    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
    }

Code-behind (Page is not cached):

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    Response.Flush();
}

Code-behind (Page still is not cached):

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    Response.Cache.SetCacheability(HttpCacheability.Server);
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
    Response.Flush();
}
  • 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-13T15:04:00+00:00Added an answer on May 13, 2026 at 3:04 pm

    Okay, I think I have a partial answer for you.

    From here:

    Output cache module populates the
    IHttpCachePolicy intrinsic in
    BeginRequest stage if a matching
    profile is found. Other modules can
    still change cache policy for the
    current request which might change
    user-mode or kernel mode caching
    behavior. Output cache caches 200
    responses to GET requests only. If
    some module already flushed the
    response by the time request reaches
    UpdateRequestCache stage or if headers
    are suppressed, response is not cached
    in output cache module
    .

    That article is IIS7 specific, so not sure how this translates across to other versions, but it’s probably similar. UpdateRequestCache is one of the HttpApplication pipeline events, and it occurs after an IHttpHandler (e.g. your Page object) has finished handling the request.

    So… it doesn’t look good for performing a flush inside your Page.

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

Sidebar

Ask A Question

Stats

  • Questions 297k
  • Answers 297k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer accept_nested_attributes_for add the possibility to ActiveRecord to be able to… May 13, 2026 at 7:13 pm
  • Editorial Team
    Editorial Team added an answer When you create the vector, it allocates room for the… May 13, 2026 at 7:13 pm
  • Editorial Team
    Editorial Team added an answer Odd. I have used Text from codebehind to change the… May 13, 2026 at 7:13 pm

Related Questions

I am using System.IO.FIle.ReadAllText() to get the contents of some template files that I
I have embedded a Python interpreter in a C program. Suppose the C program
I'm currently testing browser compatibility with IE7 for an app that I built initially
I have some code that I had to write to replace a function that
I have some code i'm revewing, which is used to convert some text into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.