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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:55:02+00:00 2026-05-14T21:55:02+00:00

There may be an easy way to do this but I can’t see it…

  • 0

There may be an easy way to do this but I can’t see it…

I created a simple Http Module that starts a timer on the PreRequestHandler and stops the timer on the PostRequestHandler to calculate the time it took the page to load.

I then create some simple html and write my results to Response.Write. Since I’m doing this in the PostRequestHandler it’s adding my results after the </html> tag. That’s fine for testing but I need in a scenario where the page needs to validate.

I can’t seem to figure out how I could manipulate the Response object to insert my results before the </body> tag. Response.Write and Response.Output.Write don’t have that flexibility and I couldn’t see a way to work with the Response as a string. Am I missing something easy?

  • 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-14T21:55:03+00:00Added an answer on May 14, 2026 at 9:55 pm

    To do this, you’d have to implement your own stream object and use that as a filter for your response.

    For isntance:

    public class TimerStream : Stream
    {
        private Stream inner { get; set; }
        private StringBuilder   responseHtml;
    
        public TimerStream(Stream inputStream) { 
            inner = inputStream; 
            responseHtml = new StringBuilder();
            // Setup your timer
        }
    
        /* Filter overrides should pass through to inner, all but Write */
        public override void Write(byte[] buffer, int offset, int count)
        {
            string bufferedHtml = System.Text.UTF8Encoding.UTF8.GetString (buffer, offset, count);
            Regex endTag = new Regex ("</html>", RegexOptions.IgnoreCase);
    
            if (!endTag.IsMatch (bufferedHtml))
            {
                responseHtml.Append(bufferedHtml);
            }
            else
            {
                // insert timer html into buffer, then...
                responseHtml.Append (bufferedHtml);
                byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes (responseHtml.ToString ());            
                inner.Write (data, 0, data.Length);            
            }
        }
    }
    

    Then, in your HttpModule, you’d add this to your BeginRequest:

    // Change the Stream filter
    HttpResponse response = context.Response;
    response.Filter = new TimerStream(context.Response.Filter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way to recursively ZIP a directory that may or may
This may not be possible for the carousel but is there a way to
Is there a way to save a configuration so that a hook may work
This may be a silly question I don't know. Is there a way to
Is there a way in an XML schema to specify that an element may
I am pretty new to rails so this may be an easy question, but
I can't beleive there's no easy way to do such a basic thing like
This may be a bit obscure, but I'm developing a viewer app that chunks
I'm wondering if there's an easy way (like using strtotime) whereby I can get
Ok, this is a very interesting question and there may not be any easy

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.