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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:43:18+00:00 2026-05-25T02:43:18+00:00

The context I have an Asp .Net web application with some pages that inherit

  • 0

The context

I have an Asp .Net web application with some pages that inherit from a base class “BasePage”.
This BasePage class inherits from System.Web.ui.Page and I’ve overriden the Render method so that I can intercept the HTML stream before it is sent to the client browser.

Here is the code of my Render method :

protected override void Render(HtmlTextWriter writer){

    MemoryStream memoryStream = new MemoryStream();

    try
    {
        using (StreamWriter streamWriter = new StreamWriter(memoryStream))
        {
            var textWriter = new HtmlTextWriter(streamWriter);
            base.Render(textWriter);
            textWriter.Flush();
            memoryStream.Position = 0;

            using (StreamReader reader = new StreamReader(memoryStream))
            {
                string finalHtml = reader.ReadToEnd();

                // Processing filters
                finalHtml = FilterManager.ProcessFilters(finalHtml);

                // Writing output to client
                writer.Write(finalHtml);
                reader.Close();
            }
        }
    }
    catch(ObjectDisposedException)
    {

    }
    finally
    {
        memoryStream.Dispose();
    }
}

So far, so good. It works. The reason I didn’t use the response filtering feature is that I knew it wouldn’t be compatible with Post-cache substitution

Yes. I do also want to use outputcache substitution. For testing purposes, I’ve added a small asp .net control in my aspx page :

<asp:Substitution runat="server" id="UnCachedArea" methodname="GetFreshDateTime" />

with the corresponding static method int the code behind :

protected static string GetFreshDateTime(HttpContext context)
{
    return DateTime.Now.ToString();
} 

… and… it works !! I’ve both my filters working only on the first page load and the substitution occuring for every refresh I make on the page.

The problem

The substitution string is inserted at the wrong place, just after the opening body tag whereas my susbtitution control is located at the very bottom of the page, in the footer.

Any clues ?

  • 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-25T02:43:19+00:00Added an answer on May 25, 2026 at 2:43 am

    It’s because you have modified the render to flatten the output into a single string, and this is what gets cached.

    Normally with donut caching the cached render output leaves dynamic region markers in the cached response for the substitution blocks that are populated post-cache. In writing a string directly into the HtmlTextWriter you have broken the ability for ASP.NET to do this. It’s the same reason why you cannot use ResponseFilters.

    Scott Gu has at good article on the subject

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

Sidebar

Related Questions

Have some strange behaviour regarding output caching in an ASP.NET 4 application on IIS
In a small ASP.NET 2.0 web-application, I have two ASHX handlers (one sync, one
What choices do I have for creating stateful dynamic content in an ASP.Net web
Setting up ASP.net MVC with Linq2SQL or Entity Framework's context to have scaffolding work
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have a winforms application that presently ships with a chm file for context-sensitive
I am implementing a web application using ASP.NET MVC3. In the application I want
I have a web site in asp.NET 4 (C#). I’m trying to find a
I'm working on a web application project using ASP.NET MVC3 and database in SQL
I'm new to ASP.NET and want to have an asp:content control for the page

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.