• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Record time logged in

Please let me know if there is a way I can record the amount of time a user is logged in on my ASP.NET (C#) website.

Thanks!
0
dshrenik
Asked:
dshrenik
  • 3
  • 2
  • 2
  • +1
3 Solutions
 
NavneetCommented:
0
 
dshrenikAuthor Commented:
Can I do this without getting into MySQL? Thanks!
0
 
disruptCommented:
I would use google analytics as it tracks duration as well.

http://www.google.com/analytics/

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
chandrasekar1Commented:
Then you can go with storing the log details in some of the ways below
1.      Storing in XML (not recommend, if the user size is growing in MB’s)
http://www.codeproject.com/KB/XML/ReadWriteSettings.aspx
2.      Storing in SQLite (powerful standalone small DB)
http://www.codeproject.com/KB/cs/SQLiteCSharp.aspx 
If you don’t want to store the user details, but want to track the site visitor’s count, then you can go with Google analytics or other visit counter meter available.
0
 
NavneetCommented:
Hi!

Yes just you needd to store the start time in some session variable and at the
Session_End  calculate.

Thanks!
0
 
dshrenikAuthor Commented:
@navneethegde:
Could you elaborate a little more. If possible, can you provide some sample code? Thanks!
0
 
chandrasekar1Commented:
Create the GLOBAL.ASAXin the solution and replace the below code on Session_end event
protected void Session_End(Object sender, EventArgs e)
{
    if (Session["USER"] != "" &&  Session["USER"] != null)
    {
        //Insert the Userdetails to DB/XML
         logdetails(Session["USER"].ToString());

       //empty the User Session
        Session["USER"] = "";
    }
}
0
 
NavneetCommented:
Hi!
    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started// You can set when user 's login is Passed successfully.
        Session["myTimeStart"] = DateTime.Now;
    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.
        Session["TotalTime"] = DateTime.Now - DateTime.Parse(Session["myTimeStart"].ToString());
    }

Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now