Last post May 22, 2009 08:44 AM by peter.str
May 22, 2009 04:24 AM|peter.str|LINK
In an earlier website I created using normal ASP.NET I came up with a solution to modify the page from an HttpModule. That solution was created to handle stuff lige tracking engines, google tracking, site catalyst, etc. The site was deployed in different
countries, and in each country they wanted their own tracking. So by implementing this solution, I could keep the tracking logic separated from the normal web pages and master pages.
I tried to do some of the same on an MVC project I'm working on. But I have a problem finding the page to modify. The current HttpHandler is not the page as it was in ASP.NET but an MvcHandler. Is there any way I can get the ViewPage after a controller has
delegated control to a view?
Here is an HttpModule implementation that resembles the one I created for ASP.NET.
public class MyScriptModule : IHttpModule
public void Init(HttpApplication context)
context.PostMapRequestHandler += context_MapRequestHandler;
void context_MapRequestHandler( object sender, EventArgs e )
IHttpHandler handler = HttpContext.Current.Handler;
if (handler is Page)
Page page = (Page)handler;
page.PreRender += PagePrerender;
public void PagePrerender( object sender, EventArgs e )
(HttpContext.Current.Handler as Page)
.ClientScript.RegisterStartupScript( typeof( MyScriptModule ), "", "alert('test')", true );
public void Dispose()
May 22, 2009 07:05 AM|aditya1986|LINK
yes we can modify only the URL using http module
for example u check the procedure how to write http module in above link
i think the links may helpful to understand the httpmodule or httphandlers
May 22, 2009 08:44 AM|peter.str|LINK
Thanks for the reply, but it didn't really answer my question.
Those links gave general description of HttpModules and HttpHandlers as a concept, a concept that I do understand already.
The question is more: How can I from an HttpModule get access to an object hierarcy that reflects my page, so that I may change that hierarchy directly, something that was very easy in ASP.NET (as you can see from my example), but I cannot find the relevant
properties anywhere when using ASP.NET MVC to expose the ViewPage object that represents the page being output.