I have written a SP which maintains users log in and log out history,it works fine when any user logs in or clicks on log out,problem is that as per need its not to allowed to keep the screen idle for 1 minute or more then in the log out column Null value is passed.
SP
Create proc usp_trackuserlogindetails
@username varchar(50) = null,
@command int = 0
as
BEGIN
if(@command = 0)
begin
insert into userlog (USERNAME,LOGIN,LOGOUT) values (@username,Getdate(),Null)
end
else if (@command = 1)
begin
update userlog set logout = getdate() where username = @username
end
END
Method
public void Logout()
{
string UserName = Session["username"].ToString();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
con.Open();
SqlCommand command = new SqlCommand("usp_trackuserlogindetails", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@username", Session["username"].ToString());
command.Parameters.AddWithValue("@command", 1);
command.ExecuteNonQuery();
}
Button
<asp:LinkButton ID="lnklogout" runat="server" onclick="lnklogout_Click">Log Out</asp:LinkButton>
protected void lnklogout_Click(object sender, EventArgs e)
{
Logout();
Session.Abandon();
Session.Clear();
}
Web Config
<sessionState mode="InProc" timeout="1"></sessionState>
Sample table result
Id Uername Login Logout
1 Test 2014-01-14 17:00:49.420 2014-01-14 17:01:04.937
2 Test 2014-01-14 17:02:04.687 Null
Here when user manually clicks the log out button then 1(table above) is the output.
When user leaves the screen idle then after 1 minute the page goes to the Login.aspx page if the user tries to do somthing on the current page,here 2(table above) is the output can i store some hard core value instead of Null like Session expire or the exact session expires time.