I am creating a web site in visual studi开发者_如何学编程o 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 ?
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.
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.
精彩评论