Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends

I am using asp.net C#. I want to kill session of current page when user leave that page. Any suggestions???

Thanks
Posted

use..session.abandon()..as soon as the user logs out...
   
Comments
bbirajdar 12-Oct-12 3:23am
   
what if the user closes the browser window instead of logging out ?
Nandakishore G N 12-Oct-12 3:59am
   
thats wat i told...regiis...when user moves out to the other page or logs out he has to kill the previous session and could hav created new session..in the next page..that is y, i have mentioned abandon()...becoz we dont know wat the usr does..he may click on next page or may close the browser..therefore it is better to abandon()..before he does something....therefore even,i agree with wat zoltan said.
bbirajdar 12-Oct-12 4:53am
   
Okay.. I am still not clear.. In which event do you propose this code to be called in case the user closes the browser?
If you would have been done a little research, you would have been found, that this is not possible in the way you think. Why? Because the server has absolutely no connection to the client after the page data is sent. Thus it can not rely on any event happening on the client. Your only reliable option is to fine-tune the session timeout and, if the resource expenses are acceptable in your environment, to do scheduled background ajax calls to keep the session alive. Be aware that this later approach has to be planed really carefully. Of course, you still have to encourage your users to log out before closing the browser window.

[Update]
Why do you want to kill the session? Just delete it's content - or leave it. But the problem is the same, and you have to address in other way. Leaving a pages is not the same as closing a window on the desktop. You can try to catch onunload and onfeboreunload on client side, but you can't be sure that it will be fired, and you get notified.
What you can be sure about is when the page is loaded. At that point you can decide if it is a new dashboard session or not, and reset the proper part of the session if needed.
   
v3
Comments
bbirajdar 12-Oct-12 3:25am
   
I agree with Zoltan. There is no fool proof method to do this. Thats why we set a session timeout so that when the user is idle for a period, either by inactivity or when he closes the browser, his session is destroyed automatically after the specified time.
I am not asking to kill session on logout, I just want if user are on dashboard.aspx page when he click on any link and leave this page dashobard.aspx and reach on dashoarddetails.aspx page. Then the session i am using on dashobard should kill when he left dashobard page. That is what i want??

Regards
Prince Kumar
Asst. Software Engineer
ENest Technologies
   
Comments
Zoltán Zörgő 12-Oct-12 5:12am
   
1) This is not the same issue as your first post
2) This is not a solution, it is an update of your original post.
3) See my update
4) "That is what i want??" - this means, that you don't know what you want :(
if u using master page or logout button u can write session.abandon();
   

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