9

我试图在“Application_Start”方法的 global.asax 文件中分配 PreSendRequestHeaders 事件。但这不起作用。

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

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

OnPreSendRequestHeaders 没有被调用,为什么?是否可以在 global.asax 中分配 PreSendRequestHeaders 方法?

4

1 回答 1

11

只需使用:

protected void Application_PreSendRequestHeaders(Object source, EventArgs e)
{

}

或实例化处理程序:

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

protected void OnPreSendRequestHeaders(object sender, EventArgs e)
{
    // should work now
}
于 2012-07-11T12:52:21.677 回答