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

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.
 
A

Alan Samet

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top