IIS 7 integrated pipeline - modifying the response HTML

922 views Asked by At

I'm trying to write an IIS extension that modifies the response HTML for a request as it is sent back to the client. I know that traditionally this would be the work of an ISAPI filter however I'm a .Net developer and I've read that implementing an ISAPI filter in .Net is a bad idea.

I have read in a few places that the shiny new integrated pipeline mode of IIS 7 should now allow me to writes modules in .Net that provide the same functionality as ISAPI filters by implementing IHttpModule, however I can't work out how to modify the response HTML for non ASP.Net requests.

The only resource I have found on how I might do this is this article however this doesn't appear to work for non ASP.Net resources or in cases where HttpApplication.CompleteRequest is called, even if the integrated pipeline mode is enabled.

How can I write an IIS module in C# that allows me to modify the response html / data for all requests?

2

There are 2 answers

2
Remy On

I think you would have to route all your requests through the ASP.NET module.

0
Yahia On

Not sure that this is really feasable with .NET but checkout this http://aspnetresources.com/articles/CustomErrorPages esp. the part about installing the HttpModule - perhaps this is more a matter of how IIS sees your module.

Although I am with you that a .NET-ISAPI-Filter is a bad idea I would still check this out to see how much impact this has in your case.

A really hard option would be to implement a local proxy (i.e. either you can write a HttpListener-based server or use a library to ease implemenation) which listens on the port(s) to be exposed and reconfigure IIS to use other ports/localhost only... this way you can filter whatever you want... although that will impact performance too IMHO.