using PreSendRequestHeaders Event in global.asax

Chris picture Chris · Jul 2, 2012 · Viewed 9.1k times · Source

I tried to assign the PreSendRequestHeaders Event in the global.asax file in the "Application_Start" method. But this does not work.

private void Application_Start()
{
    PreSendRequestHeaders += OnPreSendRequestHeaders;           
}

private void OnPreSendRequestHeaders(object sender, EventArgs e)
{
   // this is not called
}

The OnPreSendRequestHeaders is not called, why? Is it possible to assign the PreSendRequestHeaders method in the global.asax?

Answer

pklosinski picture pklosinski · Jul 11, 2012

Just use:

protected void Application_PreSendRequestHeaders(Object source, EventArgs e)
{

}

Or instantiate the handler:

protected void Application_Start()
{
    PreSendRequestHeaders += new EventHandler(OnPreSendRequestHeaders);
}

protected void OnPreSendRequestHeaders(object sender, EventArgs e)
{
    // should work now
}