none
Duration between login and logout in mvc RRS feed

  • Question

  • How can i calculate the duration of user after logout in MVC?

    In login : 0 second

    In logout : X second

    • Moved by CoolDadTx Friday, May 17, 2019 1:56 PM ASP.NET related
    Friday, May 17, 2019 9:57 AM

All replies

  • At login, save a Session variable of type DateTime and initialize it to DateTime.Now.

    Session["loginTime"] = DateTime.Now;

    Then, in your logout method, read the Session variable and subtract it from the current time. This will give you the duration of the session.

    DateTime loginTime = (DateTime)Session["loginTime"];

    double seconds = ((TimeSpan)(DateTime.Now - loginTime)).TotalSeconds;


    Friday, May 17, 2019 11:13 AM
  • How can i calculate the duration of user after logout in MVC?

    In login : 0 second

    In logout : X second

    You would most likely need to do something in the Account and Manager controllers if using Identity, which can be discussed at the ASP,NET forums.

    https://forums.asp.net/

    Friday, May 17, 2019 12:58 PM
  • Please post questions related to MVC in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, May 17, 2019 1:56 PM