views:

400

answers:

2

I am learning the ASP.net membership feature.

I am wondering how I can implement so that later login session logout former login session to avoid concurrent login. I know how to check whether the user is online (by Membership.IsOnline()) and logout the current user (by FormsAuthentication.SignOut()). But I don't know how to logout the previous login session.

Any code or reference that I can read?

+1  A: 

I don't think there is an explicit way to do this.

One way to implement it would be to store some sort of log in token (session ID?) in the Cache when a user logs in. Revoke the old token each time that user logs in. Then add an HttpModule which checks this token... when a request comes in that does not match, log the user out. Alternatively, put this logic in a master page, or a page object from which all your app pages inherit.

Bryan
That means I need to store the session ID to somewhere.Applicaton["login"] = Session.SessionID or Cache["login"] = Session.SessionID or Database? Which is better?
Billy
I would use Cache so that it would automatically get cleaned up on expiration.
Bryan
A: 

This article has the same implementation but more explained and with all the code required:

http://teknohippy.net/2008/08/21/stopping-aspnet-concurrent-logins/

Manuel Castro