How to capture the rendered HTML for asp.net page?

  • Thread starter Thread starter Paul W
  • Start date Start date
P

Paul W

Hi - I want to be able to capture the html generated by one of my pages. Is
there any way to do this from within the application, or must I use some
form of 'screen-scraping'. If screen-scraping, can someone point me in the
right direction and indicate how I get past the login screen, etc.(uses
forms authentication)? Thanks,

Paul.
 
Override the page's Render Method as follows:

protected override void Render (HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
HtmlTextWriter tw = new HtmlTextWriter(new
System.IO.StringWriter(sb));
//Render the page to the new HtmlTextWriter which actually writes to
the stringbuilder
base.Render(tw);

//Get the rendered content
string sContent = sb.ToString();

//Now output it to the page, if you want
writer.Write(sContent);
}
 
Back
Top