Reputation: 857
I have a web forms website using Windows authentication. I am trying to write to a table when someone signs in.
Inside of Global.asax.cs I have the following:
private void Application_PostAuthorizeRequest(object sender, EventArgs e)
{
LoginTracking.Log(User.Identity.Name);
}
This works but it logs 3 times per page the user visits. I'm guessing it's because each page request verifies the logged in user and the event fires. Is there an event for something like "new login session" that only fires once after they log in and won't fire again until they sign out and back in again? My end goal is have the user open the page, login, and the page writes 1 line to the table and that's it.
Upvotes: 0
Views: 491
Reputation: 5689
Assuming you're using ASP.NET session state in your web app, you can use the Session_Start
method in Global.asax.cs
protected void Session_Start(object sender, EventArgs e)
{
LoginTracking.Log(User.Identity.Name);
}
Upvotes: 3