简体   繁体   English

ASP.NET MVC4 - Session_End - 如何在Global.asax的Session_End中获取当前登录用户的名称?

[英]ASP.NET MVC4 - Session_End - How can I get the currently logged on user's name in Session_End of Global.asax?

My issue is that once Session_End executes in my Global.asax, the HttpContext.Current object no longer exists- probably as expected, I would imagine. 我的问题是,一旦Session_End在我的Global.asax中执行, HttpContext.Current对象就不再存在 - 可能正如预期的那样,我想。 So, what I'm trying to do is once the session ends, update my Logins table for the user currently logged in and set their LoggedIn status to False. 所以,我要做的是一旦会话结束,为当前登录的用户更新我的Logins表并将其LoggedIn状态设置为False。 Here's my Session_End: 这是我的Session_End:

protected void Session_End(object sender, EventArgs e)
{
    Helpers.OperationContext.UpdateIndividualLogin();
}

As you can probably guess, I can try to pass in: 你可能猜到,我可以试着传入:

System.Web.HttpContext.Current.User.Identity.Name

But this object no longer exists because I can only imagine that it's already been disposed of. 但是这个对象不再存在,因为我只能想象它已经被处理掉了。 So, is there any way I can grab the currently (or previously current) user's name? 那么,有什么方法可以获取当前(或以前当前)用户的名字?

You can do this by storing the information you want (in this case the user name) in Session. 您可以通过在Session中存储所需信息(在本例中为用户名)来完成此操作。 You can store it when the user is authenticated. 您可以在用户通过身份验证时存储它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM