Event to capture when the authenticated user is not authenticated

I am mainly looking for an event opposite to FormsAuthentication_OnAuthenticate. I want to delete some values ​​from the database when the user logs out. I tried to put it in the Session_End event, but it seems that the user has already left by the time this is done.

Update: If I can’t determine when a specific user has not been authenticated (i.e. due to a session timeout), is there a way to get a list of all authenticated users currently? If I could, then in Session_End, I could just delete entries from the database that are not associated with authenticated users.

+3
source share
4 answers

Session_End is not protected from fire - if you do not use InProc sessions, for example, it does not work at all. If your application restarts or dies, it does not work again.

It would be best to have this code in a generic method that you can call from numerous places:

  • In LoginStatus you can set LoggingOut - Call your method out there to deal with people who come out of the system is reasonable.
  • If you are using InProc sessions in your Session_End session, but make sure you check to see if they have already been logged out (as you saw).
  • InProc, . , , (, Session_Start, ), , , ( ). ​​

, , :

GetNumberOfUsersOnline

" , ". - , , :

GetAllUsers      // Gets all the users from the storage provider (can be paged)
FindUsersByName
FindUsersByEmail

, , " " .

MembershipUser, IsOnline - LastLogonDate LastActivtyDate - - , , , .

+2

, - . /. FormsAuthentication.SignOut().

0

Global.asax Session_End, , , .

, , . - . FormsAuthenticationTicket ( cookie), , . . , , , , .

, , , , , , .

0

If you are using an SQL provider, the aspnet_Users table has a column called "LastActivityDate". If you compare this value with the forms authentication timeout, you can find a list of users who are definitely not logged in. Your account will be low if they log out manually using the "log out" link.

0
source

Source: https://habr.com/ru/post/1702258/


All Articles