Is there a way to be notified when a user becomes logged in with an ASP.net website?
Note: A user can become logged in without visiting a “login page”. If the “remember me” cookie exists, they can hit an arbitrary page and be logged in.
When a user is logged in i want to fetch some session related information.
Note: There is the
Login.LoggedInevent. Problem is that that control doesn’t exist on every page; and the one page it is present on (Login.aspx) doesn’t callOnLoggedInevent.
In the same way that Global.asax has a global On Session Start notification:
void Session_Start(object sender, EventArgs e)
{
}
i assume somewhere there’s a On User Logged In notifiation:
void LoggedIn(object sender, EventArgs e)
{
}
Bonus Reading
- OnLoggedIn event on Login page ASP.NET
- Run custom code on login
- MDSN Logon.OnLoggedIn event
- How to update last login date if “Remember Me” set?
I think you don’t have a unique place to do that. In my case (MVC + log4net) I use this:
In
Global.asaxI check for authenticated users with pre-existing cookie.In my Account controller I check for local logins (I’m using Internet Application Template from MVC4, but you can do this in your
Login.OnLoggedInif you’re using Web forms)But I need to check for OAuth logins too, like this: