views:

79

answers:

2

I'm creating a custom module and I need to be able to read the html output that's written to the HttpResponse object. Can anyone provide direction on this?

Thanks!

+1  A: 

I think that you could intercept the data being written with a HttpResponse.Filter.

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx

There is an example here:

http://aspnetresources.com/articles/HttpFilters

I have not tried it myself yet though.

André Laszlo
+1  A: 

As André said, you may want to implement an HttpResponse filter. Alternatively to configuring the filter in the web.config file, you can also implement the following in the global.asax.cs file:

  protected void Application_BeginRequest() {
     Response.Filter = new PassThroughFilter(Response.Filter);
  }

The PassThroughFilter class derives from Stream and implements the abstract methods, then forwards them to the original filter.

For the full source code, see my blog.

John