HttpModule AcquireRequestState 事件处理程序的发送者为空
我有一个 HttpModule,如下所示:
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
}
}
我注意到应用程序池重新启动后立即出现问题,其中 null 作为 AcquireRequestState 事件的 sender 参数传递,并且我收到 null 引用异常。 一段时间后,问题似乎自行解决。
怎么会发生这种事?
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 occurring 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HttpContext.Current 应由基础结构在事件处理程序线程上设置。尝试在事件中使用静态访问器而不是发送者。
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.