Session?
-
Hi, If I close the browser window, session_end doesn't get fired. I want to do some updations in database when the user tries to close the window wiithout cliking on 'Logout' button provided. Any solution for this problem?
-
Hi, If I close the browser window, session_end doesn't get fired. I want to do some updations in database when the user tries to close the window wiithout cliking on 'Logout' button provided. Any solution for this problem?
If you close the browser, the session end will automatically called when it reached to the time out. if you want to explicitly doing something on browser close, just detect the browser close during using javascript and open some small popup which will clear the database data from server side code then close the popup also. if you find the code project asp.net forum you will find lots of similar question and answer.
cheers, Abhijit CodeProject MVP
-
If you close the browser, the session end will automatically called when it reached to the time out. if you want to explicitly doing something on browser close, just detect the browser close during using javascript and open some small popup which will clear the database data from server side code then close the popup also. if you find the code project asp.net forum you will find lots of similar question and answer.
cheers, Abhijit CodeProject MVP
Thank u. Can u give some links to refer for the solution?
-
Thank u. Can u give some links to refer for the solution?
Its not good to get client events by using the javascript. Another way is to write the code in the Session_End event similar event is there (I forgot :doh: ) there you can have you logic what you want to do whenever user session has been end. One question 1. Do you need to do update the DB no sooner user closed the window ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
-
Its not good to get client events by using the javascript. Another way is to write the code in the Session_End event similar event is there (I forgot :doh: ) there you can have you logic what you want to do whenever user session has been end. One question 1. Do you need to do update the DB no sooner user closed the window ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
Sandeep Akhare wrote:
Its not good to get client events by using the javascript.
Then how will you trap the browser close event ? if you want to detect browser close you have to use javascript.
Sandeep Akhare wrote:
Another way is to write the code in the Session_End event similar event is there (I forgot D'Oh! ) there you can have you logic what you want to do whenever user session has been end.
if you use Session.Abandon(), it will directly moved to Session_End() event in your Global.asax file, and inside that methods you can write your logic that what ever you want to implement.
Sandeep Akhare wrote:
One question 1. Do you need to do update the DB no sooner user closed the window ?
As per my understanding, he is storing some user information while user log into the system. and he is removing those in the log off. But, the problem happens when user close the browser. If user close the browser, Session_end() will only call when its time out.
cheers, Abhijit CodeProject MVP
-
Thank u. Can u give some links to refer for the solution?
Karthick_gc wrote:
Thank u. Can u give some links to refer for the solution?
You can try this one,
function DeleteUserLog()
{
, Alt+F4 , File -> Close
if(window.event.clientX < 0 && window.event.clientY <0)
{
window.open("CloseSession.aspx", "OpenWindow_Close_Session",'left=12000,top=1200,width=10,height=1');
}
}Call this method on unload of your master
Body
.onunload="DeleteUserLog()"
Now in
CloseSession.aspx
pages, you can do what ever you want and register the client script to close it automatically after doing the task. Hope this will helps you. :) BTW : I am planning for writing an article on same. Hope this will be published soon. ;) Cheers!!cheers, Abhijit CodeProject MVP
-
Sandeep Akhare wrote:
Its not good to get client events by using the javascript.
Then how will you trap the browser close event ? if you want to detect browser close you have to use javascript.
Sandeep Akhare wrote:
Another way is to write the code in the Session_End event similar event is there (I forgot D'Oh! ) there you can have you logic what you want to do whenever user session has been end.
if you use Session.Abandon(), it will directly moved to Session_End() event in your Global.asax file, and inside that methods you can write your logic that what ever you want to implement.
Sandeep Akhare wrote:
One question 1. Do you need to do update the DB no sooner user closed the window ?
As per my understanding, he is storing some user information while user log into the system. and he is removing those in the log off. But, the problem happens when user close the browser. If user close the browser, Session_end() will only call when its time out.
cheers, Abhijit CodeProject MVP
Abhijit Jana wrote:
As per my understanding, he is storing some user information while user log into the system. and he is removing those in the log off. But, the problem happens when user close the browser. If user close the browser, Session_end() will only call when its time out.
That should fine and this make sure that every time Session_End gets called 1. Please tell me what happens when system crashed or browser crashed for a perticular user... 2. depending on the client browser is not idle way as there can be many scenario there javascript may get failed. that's why i asked him is it necessary to update the DB no sonner user closed the browser? I think log information he can update when session_end gets called?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog