Problem attaching event

Vote:
 

Hi, trying to attach an event in my global.asax

DataFactory.Instance.LoadedDefaultPageData += new PageEventHandler(Instance_LoadedDefaultPageData);

Works fine och test-server and live, but not on my computer (Running vista business sp1).

 

Error msg: 


Request is not available in this context

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Request is not available in this context

Source Error:

Line 23:         protected void Application_Start(Object sender, EventArgs e)
Line 24: {
Line 25: DataFactory.Instance.LoadedDefaultPageData += new PageEventHandler(Instance_LoadedDefaultPageData);
Line 26: }
Line 27:
#20742
Jun 10, 2008 14:45
Vote:
 

Yeah, my collegues, who are developing this site, ran into that problem just the other day. This is due to, as I understood it, changes in the IIS. Instead of attaching to the event in Application_Start they had to run their code as a http module.

I'll see if I can get you some code later today.

#20750
Jun 11, 2008 1:32
Vote:
 

Here's some sample code. Hope it helps.

 

public class EventHandler : IHttpModule
{
private static bool _isInited = false;

private static string locker = "1";


public void Init(HttpApplication context)
{
lock (locker)
{
if (!_isInited)
{
EPiServer.DataFactory.Instance.CreatingPage += new PageEventHandler(Instance_CreatingPage);
//...

_isInited = true;
}
}
}
}

#20757
Jun 11, 2008 11:23