Application_PostAcquireRequestState 事件中的 HttpContext.Current.Session 怎么可能为 null?

发布于 2025-01-04 22:31:47 字数 445 浏览 4 评论 0原文

我正在尝试找出一种方法来启动 MVC Mini Profiler,具体取决于我们的开发人员是否登录到我们的生产网站。我们已经推出了自己的身份验证和授权机制,因此我需要能够检查当前会话以获取登录用户的 ID,但我似乎无法确定在哪里最好进行此检查以了解何时调用 MiniProfiler。开始();。

大多数时候, foo 在此代码示例中最终为 null,但根据此事件的 MSDN 文档,这似乎永远不可能:

protected void Application_PostAcquireRequestState()
{
    var foo = HttpContext.Current.Session;
}

此应用程序正在使用 MVC2 框架。

这怎么可能是空的呢?另外,有人对我应该在哪里启动分析器有什么好的建议吗?我的下一个猜测是我们的控制器基类中可用的任何“开始请求”事件。

I'm trying to figure out a way to start the MVC Mini Profiler depending on whether one of our developers is logged into our Production website. We have rolled our own authentication and authorization mechanisms, so I need to be able to inspect the current session to get the ID of the logged in user, and I cannot seem to ascertain where to best do this inspection to know when to call MiniProfiler.Start();.

Much of the time, foo winds up being null in this code sample, though according to the MSDN documentation for this event it doesn't seem like this should ever be possible:

protected void Application_PostAcquireRequestState()
{
    var foo = HttpContext.Current.Session;
}

This application is using the MVC2 framework.

How can this ever be null? Also, does anyone have any good recommendations where I should start the profiler? My next guess is going to be whatever "begin request" events are available in our controller base class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文