开发者

HttpModule AcquireRequestState event handler has null sender

I have an HttpModule, something like this:

public class MyModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
         context.AcquireRequestState += Context_OnAcquireRequestState;
    }

    private void Context_OnAcquireRequestState(object sender, EventArgs e)
    {
    HttpContext context = ((HttpApplication)sender).Context;
        ... etc
    }
}

I have noticed a problem occur开发者_StackOverflow中文版ring directly after the app pool is restarted, in which null is passed as the sender parameter of the AcquireRequestState event and I get a null reference exception. After some time the problem seems to resolve itself.

How could this be happening?


HttpContext.Current should be set on the event handler thread by the infrastructure. Try using the static accessor instead of the sender on the event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜