Hi...
This is a very critical problem in asp.net.
There is a one solution to call your logout function.
your can call a javascript function on browsers close event.
This is a event which get called before browser closed
<script language="javascript" type="text/javascript">
function unloadfunction() {
//Call your server side function using javascript.
}
</script>
<body onbeforeunload="unloadfunction()">
Using this javascript function you can call server side logout function.
And the second way is call logout function in global.asax file.
This event get fired when session get end.
Write down this type of code in global.asax file.
void Session_End(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
Loader ld = new Loader();
try
{
ld.Openconnection();
cmd = new SqlCommand("DeleteOnlineUser", ld.con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", Convert.ToString(Session["UserName"]));
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
ex.ToString();
}
finally
{
ld.Closeconnection();
}
}
Here i have pass user name to database.
When user click on logout then i am deleting this username from database table.
If you have any problem regarding this then you can contact me on this email.