Question

I'm using FormsAuthentication in my C#.net application and am appending to a database table every time the user logs in, to record their login time, shortly before calling FormsAuthentication.RedirectFromLoginPage or FormsAuthentication.SetAuthCookie.

This works fine.

However, if I use createPersistentCookie, when the user next visits the site, FormsAuthentication automatically logs them in and my logic isn't fired.

Is there an event that fires when the user is first authenticated upon returning to the site?

I've tried FormsAuthentication_OnAuthenticate and Application_AuthenticateRequest, but these both fire multiple times during a page load. I think they're firing once for the page load and then again each time a handler (ashx) is called?

I need a way of knowing when the user's cookie is used the first time in a session.

Thanks.

Was it helpful?

Solution

Doesn't look like there's a way to do it through FormsAuthentication or the built-in events, so instead I've used a Session variable to remember whether or not a login has been recorded for the current session.

Whenever the current user's ID is queried, I check to see if the Session variable exists. If it doesn't, I create it and record a login at that time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top