Welcome! and rules
Joel on Software
Getting HTML output from ASP.NET Page...
Anybody know of a way that I can get the HTML that is sent to the browser after an ASP.NET page has processed everything? I've been looking at the Response object to see if there's anything on it that can output the buffer before it's flushed but haven't found anything yet.
Hmm. It didn't even occur to me that such a thing would be possible. In the past I've solved that problem by either writing the capability into the CMS from the beginning, usually using a custom templating system that spits out a chunk of HTML which can be either sent to the browser or written to disk, or by using wget.
I also use a template driven system but it behaves a little differently that what you're describing. A developer basically builds .aspx templates and then I provide a few different webcontrols (html content, links, documents, etc.) that they can drag/drop onto their template. At runtime, a page request (http://www.example.com/page.html) is intercepted and translated to a request for the page's template (url rewrite to http://www.example.com/Templates/MyTemplate.aspx?pageGuid=XXX) and all the CMS controls fill themselves according to the pageGuid. Since the developer can have other dynamic things going on inside the template (like dynamic menu building, etc.) I need to actually have asp.net process the page so I can see what it'll actually render as to the browser. Once I have that I can just dump it to an .html file.
There's essentially two ways to do this. The first is the way you describe - use WebRequest and act like a browser.
Chris, would you mind describing how I can capture the output in an HttpModule? I already have one built to intercept incoming requests but I couldn't figure out how to get the HTML sent back to the browser in one of the HttpModule's event handlers (like EndRequest).
Look into Response.Filter - you can attach your own Stream here, through which all the output goes.
Fog Creek Home