How to store and get the last login activity of the user in asp.net?

Posted by Prabu_Spark under ASP.NET on 11/25/2012 | Points: 10 | Views : 1539 | Status : [Member] | Replies : 3
Hi sir,
I want to store and get the last login activity of the user in asp.net. Kindly give me the solution
for this problem.


Thanking you,

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Pavanandey on: 12/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Since there might be many users, who might login daily/randomly. so its better to save the date and time associted with the user in database

Thanks
Pavan Kumar
Mark Answer if this fits the need

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 12/6/2012 [Member] Bronze | Points: 25

Up
0
Down
Plz Mark the answer if it helps

Thanks
Pavan Kumar
Mark Answer if this fits the need

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 12/11/2012 [Member] Starter | Points: 25

Up
0
Down
string _ConnString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; 

using (SqlConnection connection = new SqlConnection(_ConnString))
{ string dateandtime = DateTime.Now.ToString();
string loggedusername = HttpContext.Current.User.Identity.Name;
string sql = "UPDATE users SET last_login_date=@dateandtime WHERE username=@loggedusername";
connection.Open();
SqlCommand cmd = new SqlCommand(sql, connection);
SqlParameter[] pram = new SqlParameter[2];
pram[0] = new SqlParameter("@dateandtime", SqlDbType.VarChar, 49);
pram[1] = new SqlParameter("@loggedusername", SqlDbType.VarChar, 49);

pram[0].Value = dateandtime;
pram[1].Value = loggedusername;

for (int i = 0; i < pram.Length; i++)
{
cmd.Parameters.Add(pram[i]);
}
cmd.ExecuteNonQuery();
connection.Close();
}


Place the above code when your session starts

Thanks & Regards

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response