HttpModule AcquireRequestState 事件处理程序的发送者为空

发布于 2024-08-15 16:57:42 字数 524 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2024-08-22 16:57:42

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文