开发者

Viewing active users in my ASP.NET web page

I store registered users to database db_register.

I want to store each user's id 开发者_Go百科to an array the time they log in.

How can I store each user id to an array?


If you are using FormsAuthentication,

  1. You will get all users from Membership.GetAllUsers();.
  2. It returns a MembershipUserCollection.
  3. Enumerate through MembershipUser on that collection.
  4. You will see a boolean property called MembershipUser.IsOnline

Populate that collection in a GridView and you can see all Users who are online.


There is a multitude of ways that you could achieve this and I think you need to supply more detaisl about how you're controlling logins etc.

If you're not using FormsAuthentication and you don't want to persist the logged on user state to the DB then I'd say your best bet would be to have a collection/list of logged on users in your Application state. So as a user logs on, you add them to the list. Something like:

(List<string>)(Application["loggedUsers"]).Add(loggedonusername);

Then, on a seprate page you could bind a grid/repeater etc. to Application["loggedUsers"].

When a user logs out or their session ends, you remove the entry from the application state.

Alternatively if you have access to modifying your DB, you could add a field to the User table (if you have one) that denotes whether or not the user is logged on - this would replace storing the users in Application state.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜