views:

213

answers:

1

Hi,

I need to rewrite the domain names on web pages served by a DLL that I have no way to change. I thought if there were events like OnFlush before Response.Flush occurs on the page I could do it all before the page is displayed. Is there a way to do this in ASP?

Thanks for your help.

P.S.: Something like Script_OnFlush in this APACHE extension: http://www.apache-asp.org/events.html


Following Nick's suggestion I have created a class that inherits from the Stream class. Response.Filter is using this class to work on the HTML content...

By overriding the Write method I managed to rewrite the domain names on the site.

    public override void Write(byte[] buffer, int offset, int count) 
    {
     byte [ ] data = new byte [ count ];
    Buffer.BlockCopy ( buffer, offset, data, 0, count );

    string myHTML = ASCIIEncoding.ASCII.GetString(data);
    string convertedHTML = myHTML.Replace("http://www.previousdomain.com", "http://www.currentdomain.com");

    data = ASCIIEncoding.ASCII.GetBytes(convertedHTML);

     _sink.Write ( data, 0, count );

    }

Thanks Nick!

+1  A: 

Yes you can overload the Response.Filter property, which acts as a filter for all content that is returned to the browser. You should do this in the PostReleaseRequestState in the Global.asax.

Nick Berardi
Isn't this about ASP? Eg. not asp.net but classic asp.
svinto
Nope, ASP.NET, if you don't want to use the Global.asax you can create your own module using IHttpModule interface.
Nick Berardi
Thanks Nick, but I need to do this somehow in classic ASP.
G Berdal
Oh then you are out of luck with anything built in. You will need to write your own ISAPI provider, using C++. Sorry Classic ASP is just a scripting language. However if you were running this on IIS 7, you could use the integrated mode to code this in the same way I mentioned above.
Nick Berardi
Thanks Nick. I'll check with IT about IIS 7.
G Berdal
You can also use a Reverse Proxy on the front end to deliver your site through ASP.NET if you are using IIS 6, sort of like I explained on my blog http://www.coderjournal.com/2008/02/url-rewriter-reverse-proxy-iis-wordpress/
Nick Berardi