1

I basically need to restrict the number of logged in users in my application. What I am doing is using Membership.GetNumberOfUsersOnline() I am getting the number of logged in users while authenticating a new user I check the number of online users to the number I want to restrict. Membership.GetNumberOfUsersOnline() works fine when a new user logs in, the problem occurs when a user signs out the value of Membership.GetNumberOfUsersOnline() does not automatically decrements. I searched over the msdn and found that this method checks the last user activity time, which doesnt support signout event. Is there any other way in Membership providers to restrict the number of users. I am using Silverlight and REST services. I am using Membership.GetNumberOfUsersOnline() at the server side.

Thanx in advance.

3 Answers 3

1

You can try ASP.NET C# Visitor Real-time Session Tracker by Sarin at http://www.sarin.mobi/2008/11/aspnet-csharp-visitor-real-time-session-tracker/

1

I'm assuming you are using an SqlMembershipProvider. If so, this is the direction I would take...

Create a class that inherits SqlMembershipProvider and override the GetNumberOfUsersOnline() and ValidateUser() methods...

using System.Web.Security;

public class MyMembershipProvider : SqlMembershipProvider
{
    public override bool ValidateUser(string username, string password)
    {
        if (base.ValidateUser(username, password))
        {
            // successfully logged in. add logic to increment online user count.

            return true;
        }

        return false;
    }

    public override int GetNumberOfUsersOnline()
    {
        // add logic to get online user count and return it.
    }
}

Now if you're using a LoginStatus control to allow users to sign out, you can use the LoggedOut event to add the decrement online user count logic there.

You will have to use your new custom membership provider in the web.config. For the type property of your membership, change it from whatever it says, something like type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" to something like type="MyNameSpace.MyMembershipProvider". I think that's all there is to it.

This solution allows you to keep using your SqlMembershipProvider provider with just a couple additions.

0

Add a new column named status in your user table in data base.The data type of that status column bit (1/0).In every 15 min check no of users are online. Use a Timer in code behind page.Check the timer and in every 15 min raise that paricular event

3
  • Thanx for reply but I am using membership tables. Is it a good idea to modify those tables? Commented Jul 12, 2012 at 6:43
  • I am not saying to modify . You can add an extra column in that table. Commented Jul 12, 2012 at 6:52
  • 1
    You're right. Adding columns will cause no harm as Sibasis suggested. But don't modify anything that was previously created by asp.net.
    – Theo
    Commented Jul 12, 2012 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.