I am trying to intercept a asp.net web request and based on a lookup replace the page thats going to be rendered to the client.
example:
If a request for “/about-us” comes to my web server, i will first see if i have a version of this in the database, otherwise i will revert to flat files.
The version I will retrieve from the database will be a .aspx page that has to be rendered and contain web controls and inline serverside script.
What is the best way to go about this?
I have tried overriding the CreateHtmlTextWriter method but this seems to be too late in the process as the TextWriter passed to this method is already instantiated.
I have also tried to Implement my own PageHandlerFactory but this seems to create an instance of Page of which I cannot seem to override its internal setting of the Response.Output stream.
Am i barking up the wrong tree here?
what is the best approach to take here?
Implement your own
HttpHandler– this can intercept the calls, you can pick stuff up from DB or from the file system and send those as a response. You simply need to implementIHttpHandlerin your class and configure IIS to use it.If all you are going to do is output text (in the form of an ASPX page), then it would not go through the IIS aspx engine. To do that, you would have to dynamically load, compile and execute such a page – a very difficult thing to do. This Microsoft KB article can be of help.