Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have table Attendance having attribute
[ID],[Engi_Profile_ID],[In_Date_Time],[Out_Date_Time],[Reason],[Remark],[Flag]

When i login it insert [int],[Engi_Profile_ID] , [In_Date_Time] ,[In_Date_Only] ,
[Reason],[Remark],[Flag] is inserted but when session expire then a query is fired for update where to write it to fire the update query is it Global.asax page or web.config page how to do it.
I know what i have done is wrong.
give me write answer.

What I have tried:

void Session_Start(object sender, EventArgs e)
{
HttpContext.Current.Session("Session_Name");
id = HttpContext.Current.Session.SessionID;
SqlCommand cmd1 = new SqlCommand("Update Attendence set Out_Date_Time='" + DateTime.Now + "', Flag='Close' where Engi_PRofile_ID='" + txtID.Text + "' and Flag='Open' and Replace(Convert(Nvarchar(20),In_Date_Only,106),' ','-')=Replace(Convert(Nvarchar(20),gETDATE(),106),' ','-')", con);
cmd1.Parameters.AddWithValue("@Engi_Profile_ID", txtID.Text.ToString());
}
Posted
Updated 26-Apr-16 2:44am

The only way of doing this is to use the Session_End event, but that only works with in-process sessions (that's the default, you're probably using them) however it's very unreliable and you'll find it doesn't always fire. This is just one of those things you shouldn't do, the web is stateless so servers don't know if you are there or not so don't build anything that relies on knowing when the user is no longer there.
 
Share this answer
 
You can use Session_End to achieve this.

C#
void Session_End(Object sender, EventArgs E) {
    // Your Update Method
}


The Session_End event doesn't fire when the browser is closed, it fires when the server hasn't gotten a request from the user in a specific time(by default 20 minutes).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900