views:

27

answers:

2

I am creating a web site in visual studio 2008.

I want to allow the current user to log in but log off any other person logged in under the same username as the current user. (just like like Y!M does when you log in from a different location: It signs you out from the initial location) For managing log in and sign up i am using visual studio createuserwizard and log in cotrol.

Any ideeas ?

A: 

How about checking if they are already logged on via the Application_AuthenticateRequest method in Global.asax.cs. Of course to do that you will need to initially keep some sort of look up table from where they logged in from. You could get and use the user's IP address to determine that however, proxy servers from various ISPs will put a wrinkle in that method. Alternatively, you could use a cookie to set a GUID their first time in and then check to see that same GUID is in subsequent login sessions to determine if you want to terminate their other sessions.

Its a start.

Al Dass
I've been reding about setting a GUID or chaching some info at log in but i couldn't get anything to work in practice. It would be really nice if you could provide some code also. Thx.
Cristian
A: 

After doing some extra research I came up with a solution.

Whenever a user logs in I create a session, say session["user"] = NewGuid() and I add that same GUID value into a database field for that user. (for example, in the users table I added a new column named session)

Then for every request the user sends to the web page I check whether his session value is the same as the one found in his session datafield in the data base table. If it is not, then it means that somebody else loged in using that username thus creating a new value in the session field in the datatable. In that case I log him out and keep only the last user who logged in.

Cristian