Subscribe to Subscribers

Forums » .NET » ASP.NET »

How to find out time in betwin longin and logout


Posted Date: 03 Jun 2009      Posted By:: Sanjay     Member Level: Silver    Member Rank: 2502     Points: 1   Responses: 6



hi
i want to track a time in betwin login and logout.
so how will i do this?




Responses

#384995    Author: Lalit Saini      Member Level: Gold      Member Rank: 0     Date: 03/Jun/2009   Rating: 2 out of 52 out of 5     Points: 2

you have to store in database the time of login and logout

 
#384997    Author: Mohit Jain      Member Level: Gold      Member Rank: 712     Date: 03/Jun/2009   Rating: 2 out of 52 out of 5     Points: 2

Hi Sanjay,

The same you can do on the click of the Login button and Logout button. You can count the Ticks on both the methods and easily calculate how much time the user was with your website.
Write the following code in the Login Button Click event. Make sure the code gets executed when the Login is successful.

DateTime _startTime = DateTime.Now;

Keep this time in Session variable.

Put the same code in Logout button click event

DateTime _endTime = DateTime.Now;

Now Substract the End time from start time. You will get the spent time on your WebSite.

TimeSpan ts = new TimeSpan(_endTime.Ticks - _startTime.Ticks);
double ms = ts.Milliseconds;

This time would be in MilliSeconds which can easily be converted in Minutes or Hours.

Thanks,
Mohit Jain
MCTS, MCSD.Net, MCPD.Net
Give a try, before telling No


 
#384999    Author: Kalyan      Member Level: Gold      Member Rank: 276     Date: 03/Jun/2009   Rating: 2 out of 52 out of 5     Points: 2

First u have to save Login and Logout Times in DB.
Later

TimeSpan timeSpan = toDate - fromDate;

by using this u can get timespan of login and logout times.





 
#385016    Author: Narendra Reddy vajrala      Member Level: Gold      Member Rank: 163     Date: 03/Jun/2009   Rating: 2 out of 52 out of 5     Points: 2

In this case i thought using sessions is not better way because we cant know how much time user will spent. there is a chance to expire that session.

i thought comming from database is better

in login button update logintime to respective filed to that user
and while logout updata logout time to respective filed
using time span you can get timespent.

--Naren
Be Good and Do Good


 
#385034    Author: Abhay Kumar Raut      Member Level: Gold      Member Rank: 39     Date: 03/Jun/2009   Rating: 2 out of 52 out of 5     Points: 2

store in both login and logout time.the simplest way.

DNS MVM
Team Lead at MavStack Solutions
Bhubaneswar,Odisha
Thanks and Regards,
Abhay Kumar Raut
http://mavstack.com/


 
#385621    Author: Sanjay      Member Level: Silver      Member Rank: 2502     Date: 05/Jun/2009   Rating: 2 out of 52 out of 5     Points: 2

hi
u r answers is useful.
but one more problem is created .when i stores login time which is on
"login_success" .whenever i try to refresh page it will store new refreshed date-time.
this should not happen because i want to store login time not a current time.
what should i do?
my code ------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

Label1.Text = DateTime.Now.ToString();
}
when i logout on same page my code ------
logout_click()
{
Label2.Text = DateTime.Now.ToString();

SqlDataAdapter da = new SqlDataAdapter("insert into dates values('"+Label1 .Text.ToString () +"','" + Label2 .Text.ToString () + "' )", cn);
DataSet ds = new DataSet();
da.Fill(ds);

Response.Redirect("Time_spend.aspx");
}


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Prblm with controls
Previous : Adrotator
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.