November Happy Hour will be moved to Thursday December 5th.

Get HTML Output

Vote:
 
How do I get the HTML output of another page using the PageData.GetPage method
#20906
Jun 17, 2008 14:00
Vote:
 

Hi Alok!

It depends a little on what html your trying to get.

If its just the htmlcode entered for some property (for example "MainBody") on the other page, then it would be as simple as:

PageData otherPage = EPiServer.DataFactory.Instance.GetPage(otherPageRef);
string html = otherPage["MainBody"] as string;

But, if you want to get the "complete" htmlpage (as it would have been rendered by the aspx/ascx) it would be a little trickier. The easiest solution would be to simply issue a webrequest to the page and read the returned html response stream through a StringReader.

While this works, it has the downside of hitting the server with a new request which could be both time and resource consuming, especially on a site with lots of requests.

I have done some hacks around the PageParser.GetCompiledPageInstance() which lets you "shortcut" the asp.net request by calling into the IHttpHandler directly without the need to issue a "full" webrequest and also to capture the rendered html output.

I could probably dig out some sample code for you if youre interested, just drop me a email (johan.olofsson @ episerver.com).

Regards,
Johan Olofsson

 

#20907
Jun 17, 2008 14:18
Vote:
 

If anyone's interested, I made a blog post (with sources) on how one can get a page's html without a "full" web request.

http://labs.episerver.com/en/Blogs/Johano/Dates/2008/6/Hack-Getting-the-html-from-a-PageData-in-EPiServer-CMS5/

/johan

#21018
Jun 18, 2008 15:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.