웹 응용 프로그램이 시작된 후 및 웹 요청 중에 한 번만 또는 몇 번만 실행하려고한다고 가정 해 봅니다.IHttpModule 초기화 범위에서 HttpApplication 이벤트 처리기를 바인딩 해제 할 수없는 이유는 무엇입니까?
public class WebApp : HttpApplication
{
public override void Init()
{
base.Init();
this.BeginRequest += new EventHandler(this.OnFirstBeginRequest);
}
private void OnFirstBeginRequest(object sender, EventArgs e)
{
// do some action and if everything is OK, unbind this handler,
// because we need it executed only once at the first web request
this.BeginRequest -= new EventHandler(this.OnFirstBeginRequest);
}
}
다음 예외가 발생됩니다
이벤트 핸들러는 IHttpModule을 초기화하는 동안 같이 HttpApplication 이벤트에 바인딩 할 수 있습니다.
왜 Global.asax와 Application_Start를 사용하지 않습니까? – Xaqron
어제 비슷한 질문이 생겼습니다 : [IHttpModule 초기화 중 이벤트 처리기를 HttpApplication 이벤트에만 바인딩 할 수있는 이유는 무엇입니까?] (http://stackoverflow.com/q/2781346/102112). – Alex
Xaqron, 왜 그래야합니까? 그러면 코드 샘플이 복잡 해지고 내 질문의 주제가 다른 방향으로 바뀌게됩니다. –