Why can't my host (softsyshosting.com) support BeginRequest and EndRequest event handlers? Why can't my host (softsyshosting.com) support BeginRequest and EndRequest event handlers? asp.net asp.net

Why can't my host (softsyshosting.com) support BeginRequest and EndRequest event handlers?


You need register your handlers in each HttpApplication instance. There may be several pooled instances of HttpApplication. Application_Start is called only once (for IIS 6 and IIS 7 in classic mode - on the first request, for IIS 7 integrated mode - on web app start, just before any request). So to get all working you need to add events handlers in overrided Init method of HttpApplication or in constructor of it. If you add them in constructor - these handlers will be invoked first, even before the handlers of registered modules.
So your code should look like this:

public class MySmartApp: HttpApplication{    public override void Init(){        this.BeginRequest += new EventHandler(MvcApplication_BeginRequest);        this.EndRequest += new EventHandler(MvcApplication_EndRequest);    }    protected void Application_Start(){        RegisterRoutes(RouteTable.Routes);    } }

or like this:

public class MySmartApp: HttpApplication{    public MySmartApp(){        this.BeginRequest += new EventHandler(MvcApplication_BeginRequest);        this.EndRequest += new EventHandler(MvcApplication_EndRequest);    }    protected void Application_Start(){        RegisterRoutes(RouteTable.Routes);    } }


Looks to me like you went from IIS 6 or IIS 7 Classic mode to IIS 7 Integrated mode. In IIS 7 integrated mode, the Request processing was decoupled from application start. This article explains the why's and wherefores.

To fix it, you'll need to move your code to Application_BeginRequest instead.