我尝试在" 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方法?
答案 0 :(得分:8)
只需使用:
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
}