Search code examples
asp.nethttphandlerhttpmodule

How can I programmatically modify an aspx file content before the handler handle it?


The reason I need to modify the content of an aspx (not physically, but change the content in the memory) is because there are certain custom tags I made needs to be parsed to the correct data before the entire aspx is handled by the HttpHandler.

Is there a way for that?


Solution

  • You can use Response Filters (HttpFilter) and modify content on the fly, basically after response is formed, before EndRequest your filter is called (it's a stream descendant) and you can modify it as you wish. In the HttpModule, Init method you got to install HttpFilter (Response.Filter) and it will be called for that request.

    Here is a good article :

    http://aspnetresources.com/articles/HttpFilters

    UPDATE: Maybe this is a case of XY Problem, and you can solve your problem with simple server control that will render these custom tags properly.