c# - Application_End Logout Users in global.asax -


i want ask can logout user in application_end??? ,i know when application_end invokes application_end global.asax

but want know right make users logout in application end, want enter logout date time of user.

    void application_end(object sender, eventargs e)     {         try         {             var lisloginusers = db.user_login.where(z => z.logout_datetime == null).tolist();             if (lisloginusers.count != 0)             {                 (int = 0; < lisloginusers.count; i++)                 {                     lisloginusers[i].logout_datetime = system.datetime.now;                     db.savechanges();                  }             }         }         catch (exception msg)         {             exceptionlogging.senderrortotext(msg);             response.redirect("/account/error/");          }     } 

no, can't use application_end record singout in real sites.

since application_end event not tied request there things can't - can't act on particular user or redirect response somewhere (as there no request/response start with).

indeed can wipe out or bulk update information in db, not achieve actual goals "enter logout date time of user".

application shutdown not tied user behavior - relates stopping server side code whatever reason (i.e. restarting site due update or inactivity). user's point of view still may looking @ pages , consider "logged in".

in case have non-trivial site more 1 server there no correlation when each server restarts iis process making application_end unfit "user logged out" 1 server can actively serve requests while other restarting.

your best bet timeout user sessions either explicitly (i.e. 40 minutes signing in) or sliding expiration either updating time on every request / heartbeat ajax pings page.


Comments