I'm using Forms Authentication (and the built in Login controls) and letting users click the "remember me" checkbox when logging in. When they return to the site, they are automatically logged in as expected. Is there an event I can catch when this happens? I've been studying the FormsAuthenticationModule.Authenticate event, but I'm not sure that is the correct approach.
views:
300answers:
3How do I set a session variable when a user is automatically logged in via Forms Authentication?
First of all, look into using the Login control that's available in 2.0+ (as I remember). There is a Authenticate event you can handle on that control, which is where you can set your session variable.
Additionally, let's assume after authenticating the user is taken to some "home" page. So you can set your session variable inside the "home" page's Load event handler.
You might look at Session_Start in global.asax and see if you can detect at that point if the user is authenticated and, if so, set your variable from there. You'll probably need to reference the session from HttpContext.Current.Session (similarly with User). You might also want to look at an HttpHandler that registers an event handler for OnAuthenticate and check/set your variable there.
Look in the Application_AuthenticateRequest event in Global.asax.
http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx
This event fires after the user has been authenticated (via having manually signed in or with a cookie). From there, you can do what you need. You can interrogate the Page.User object for info about the logged in user,
http://msdn.microsoft.com/en-us/library/system.web.ui.page.user.aspx