Jeffrey Palermo (.com)

Sponsors

The Lounge

Wicked Cool Jobs

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
How to capture page output before it is rendered - level 300

If for some reason you need to capture page output either to log it, analyze it or do a global string replace, then you will need to intercept the rendered Html before it makes it to the wire on the way to the client.  Here is a code snippet that will do just that.

protected override void Render(HtmlTextWriter writer)

{

    StringBuilder sb = new StringBuilder();

    HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(sb));

    base.Render(htw);

    writer.Write(sb.ToString());

    Trace.Warn(sb.ToString());

}


The StringBuilder will get the content, and you can do with it what you please.  Then just make sure to call writer.Write( ) to render the final content to the Response stream.

Posted Thu, Nov 25 2004 7:47 PM by Jeffrey Palermo

[Advertisement]

Comments

mortb wrote re: How to capture page output before it is rendered - level 300
on Thu, Nov 25 2004 10:39 PM
This is good stuff!

This makes me able to write the page directly to a file which I will zip and make downloadble
Devlicio.us