Filter output by using a HttpModule

  • Thread starter Thread starter Thomas
  • Start date Start date
T

Thomas

I want to be able to implement a filter that manipulates the output from the
server... Maybe replacing some words, or highlighting a search string, or
some other fancy feature...

I want to make this code reusable to all my applications, and by making this
as a HttpModule I can implement this feature on existing .Net applications
by editing the we.config and nothing else...

My problem is that that I can't get this to work.

Some pseudo-code:

public class PostProcessingModule : System.Web.IHttpModule {
public void Init(System.Web.HttpApplication context) {
// What event should i use ....
// How do I reference the output and replace values
// How do I write my own manipulated stuff to the client
}

public void Dispose() {}

}
 
Thx!

This solves my problem... almost ;-)

What if I want to implement more than one filter... lets say I have a
SearchHighlightModule and a WordCensorModule ... The Response object can
only supprt one filter... I was hoping to be able to do this directly from
the httpmodule, but maybe that is impossible...
 
I figured it out... still using Response.Filter

HttpResponse res = HttpContext.Current.Response;

if ( res.ContentType == "text/html" ) {
res.Filter = new CensorFilter(res.Filter);
res.Filter = new HightLightFilter(res.Filter);
}

In fact there was nothing to figure out... It just works :-D
 
Yes, you can do that. Or you can make seperate filters and force their
order of priority by their position in order in web.config.

Glad you have a resolution.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
Back
Top