Click here to Skip to main content
15,918,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm going through this problem of updating LogOut time on Server connection lost(Internet) from my web application. I need to update the logout time on below scenario's. Help needed in this.. I'm new to Asp.Net

1. On abrupt closing of Browser tab or window.
2. On Connection lost with the server.(When one has logged into application and the internet connection is lost)

Your replies are very much needed....

Thanks & regards,
Puneeth
Posted

There is no way to do this directly.
Your application could be using many browsers and each of them would behave differently on closing using the cross button.

Have a session timeout so that the user is logged out successfully.
 
Share this answer
 
SQL
the Session_End event is only fired if you have InProc sessions. SQL or state server session management will not fire this event. If you can, get back to InProc sessions and use this event.

The next best thing would be to have a "last access time" stored somewhere for your users and use that to detect a timeout of the session. The implementation of such a job is complicated though (you can miss logout events if a user logs in/out rapidly for example)...
 
Share this answer
 
v2
Hi Guys,

Thanks for the reply...

For scenario 1, I'm trying to handle in the below way in the Master Page.

I'm calling Logout.aspx using ajax on mousedown event of my Master page <body> element.
Till now working fine with IE, Chrome and Firefox.

<body onbeforeunload="bodyUnload();" onmousedown="clicked=true;">


<script language="javascript" type="text/javascript">
var clicked = false;

function bodyUnload() {
if (clicked == false)//browser is closed
{
$.ajax({
type: 'POST',
url: './../Common/LogOut.aspx',
data: {},
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (r) { },
error: function (e) { }
});
}
}
</script>



public partial class Aspx_Common_LogOut : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session.Abandon();
}
}

But Scenario 2 is not implemented. How can I track whether my client is connected with the server or not. If the connection is lost I need to update the logout time in Database.</body>
 
Share this answer
 
v2

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