Saturday, December 15, 2012

Log me out!!!


The most typical problem in silverlight that comes with no concrete solution is logging out user when the browser is closed or the application crashes. You see, what if your application met with a user who is so lazy for logging out properly, so instead he closes the browser or the application’s tab? In that case, the user won’t get logged out, and the instance of the user still remained on the server. The remained garbage instance stays their as a ghost which can resurrect any time  and cause conflicts in the application.
There is no way you can perform the log out operation in silverlight when the browser closes. But here is the catch, although there is no direct way, there is  an indirect way. Silverlight’s code, which basically renders into java script at the client, makes the life easy. Why not we directly write java script’s function that do log out for us?  Well that’s what we are going to do.
What we need is to catch the browser close event from java script, then call a silverlight function to log out the user and halt the  execution for sometime, then we explicitly close the browser.
1
Above function will be called when the browser is closing. We’ll first check weather the user who was logged in is still authenticated, i.e. he didn’t logged out and closed the browser.
2
The IsStillAuthenticated() function will return true if user is still logged in, andfalse if user was logged out. Next, if the user is still authenticated it will be logged out or else the browser gets closed. Now look at the Logout function for a while.
3
The Logout function is basically calling a function Logout() of the AuthenticationDomainService. This request to return the result takes a lot of time. And keeping the browser open for that particular amount of  time is not a good idea. Therefore, what we are doing here is waiting for at least 1 second before closing the browser, meanwhile the browser is generating packets to be transferred to the server to process logout operation. Once the packets are send, we are not waiting for the response from the server, and let the browser close.
So, if the server accepts the request the user will be logged out, but there are also chances that server rejects the request. In the later case, the user’s instance will remained in the server and he did not logged out. As we’ve seen, the javascript technique is useful, it do produce results in some cases, but also fails in others.
Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2013 Neelesh Vishwakarma
Posts RSS Comments RSS
Back to top