Text replacement moduleRSS

1 reply

Last post Apr 10, 2015 10:38 AM by Jagermeister

  • Text replacement module

    Apr 07, 2015 08:49 AM|Jagermeister|LINK

    Hello everyone,

    I was writing an IIS Module to insert a banner warning about cookies in all websites hosted in our servers. My idea was to catch the response in beginResponse step, locate the tag <body> and do a string replacement to add the banner (btw, if anyone thinks of a better solution, please let me know).

    For that I used Rick Strahl's replacement filter: http://weblog.west-wind.com/posts/2009/Nov/13/Capturing-and-Transforming-ASPNET-Output-with-ResponseFilter

    I have a couple problems, which I don't know if they inherent to IIS modules or issues with my implementation:

    - If static compression is enabled for the site, the module fails and I get an "Error decoding the website" error message in the browser.

    - Even thoud the I only apply the replacement to content type "text/html", images are not shown if the module is loaded.

    Any help or direction about how to solve these issues, or maybe about taking another direction to add these banners, would be greatly appreciated. Thank you very much


  • Re: Text replacement module

    Apr 10, 2015 10:38 AM|Jagermeister|LINK

    I reply to myself, in case it is helpful for anyone:

    >> "Even thoud the I only apply the replacement to content type "text/html", images are not shown if the module is loaded."

    For some reason when checking Content Type (Context.Response.ContentType) it always results in "text/html", even for images or CSS files, so the replacement was being done on images. Checking headers with fiddler the content type is correct, this only happens when the module captures the response.

    Maybe it is caused by the cycle when the replacement is being done, BeginRequest, but it also happened with practically all other cycles I have tried.

    For the moment it seems to be working by checking the extension, instead of the content type.

    Now I'm still puzzled about the static compression problem..