Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi ,
I am using form authentication in my application . I am using login control too.

The issue is that after login when i close browser and re run application again it shows logout instead of login however if i go to another page than i am getting session value null and ask to login me again .



My requirement is that after closing browser i need to log out automatically.





Thanks in advance.
Posted

 
Share this answer
 
Comments
SRS(The Coder) 3-Jul-14 1:34am    
This example will also not work in case of browser not closed manually. Also itself it mentions that :-
"There is no fool-proof technique to catch the browser close event for 100% of the time."
Kornfeld Eliyahu Peter 3-Jul-14 5:19am    
True - there is no way to ensure (electricity out), but this article provides a solution will work for most...
You can handle the event named 'onbeforeunload' of current window and within that event handler you can call the logout operation of the application.

Make an ajax call to the logout operation from the page methods and end the session on window closing of browser.

Please refer this link to get some idea how to start with :-
http://forums.asp.net/t/1969069.aspx?Call+c+method+inside+onbeforeunload+event+JS[^]


Hope this is of help to you.
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 2-Jul-14 7:52am    
onbeforeunload event can't help you here! What if user decides not to close the window after all?!
Uddhalak Mishra 2-Jul-14 8:55am    
I have tried it before but both of solution not work for me
SRS(The Coder) 2-Jul-14 8:59am    
onbeforeunload is more efficient because it does not run in competition with the actual closing of the window and is triggered before onunload.

Please see this :-
http://stackoverflow.com/questions/6895564/difference-between-onbeforeunload-and-onunload

Even handling both is a better choice it seems as below mentioned in this post.
Kornfeld Eliyahu Peter 2-Jul-14 9:10am    
I suggest you to learn actually what unbeforeupload doing before accepting answers on SO...
https://developer.mozilla.org/en-US/docs/Web/API/Window.onbeforeunload - "When this event returns a non-void value, the user is prompted to confirm the page unload." That non-void value is the message of the prompt. however closing anything from within the event can lead to disaster as the user can decide NOT to close the window!!!

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