Filter output by using a HttpModule

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() {}

}
 
T

Thomas

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

Thomas

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
 
J

John Timney \(Microsoft MVP\)

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
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top