EPDataFactory in HttpModule

Hi. I've created a new IHttpModule. In this module I would like to fetch data from the EPiServer.Global.EPDataFactory.CurrentPage, but this always returns NULL. Is this property not available at this level? I've implemented both the BeginRequest and EndRequest for testing purposes, but none of them retrieves CurrentPage. Any suggestions? Frank :)
Sep 16, 2005 14:00
DataFactory.CurrentPage will always be null. The documentation states: "This IPageSource implementation simply returns null since DataFactory has no concept of a "current" page." CurrentPage is only available on templates. Also, BeginRequest is too soon (I think), the actual loading of the page is not done until the TemplatePage (PageBase) recieves control. But, depending on what event you listen to, you could cast the HttpContext.Current.Handler property to a PageBase, and use the properties directly from that. The trickiest things about HttpModules are often getting the timing right. /Steve
Sep 16, 2005 16:48
Hi. Found the right timing... :-) private void context_PostRequestHandlerExecute(object sender, EventArgs e) { if(HandleCurrentResponse()) { IHttpHandler handler = HttpContext.Current.Handler; PageBase page = null; if(handler is PageBase) page = (PageBase)handler; if(page != null) { EPiTrackerPage tracker = new EPiTrackerPage(page.CurrentPage); tracker.SavePage(); } } } private bool HandleCurrentResponse() { return HttpContext.Current.Response.StatusCode == 200; } This was the only event (as far as I know and tested) that had both the session and the handler objects available with correct data in it. The HandleCurrentResponse() method just checks the statuscode for the current request. I'm not interested in logging all 404 errors that pops up in a request (like missing images etc.). 200 = OK. Also make sure to add the event handler in Init: context.PostRequestHandlerExecute += new EventHandler(context_PostRequestHandlerExecute); Thank you for your help! Frank :)
Sep 29, 2005 15:38
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.