Where is GetAllUsers in membership provider?
Asked Answered
C

3

8

I looked at membership provider documentation and there should be two GetAllUsers method in membership provider (http://msdn.microsoft.com/en-us/library/system.web.security.membership.getallusers ).

But when I look at methods exposed by System.Web.Security (in

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.ApplicationServices.dll )

It only has one method (the one that has paging capability).

Where can I find a method to return all users from database? It seems there is no way to get list of all users or find how many user is in the database.

--Update

looking at System.Web.Security, i found that SqlMembershipProvider is defined as follow:

public class SqlMembershipProvider : System.Web.Security.MembershipProvider

but this class doesn't have any public GetAllUsers() method.

How can I access its base GetAllUsers method?

Cheesecloth answered 18/5, 2012 at 9:31 Comment(5)
And what happens when you actually call "Membership.GetAllUsers()" ?Hakon
Getting this error: Error 17 No overload for method 'GetAllUsers' takes 0 argumentsCheesecloth
Which version & type (Original/MVC) ASP.Net are you using?Proficiency
I am using MVc 3 with .Net 4.Cheesecloth
Hi Mans, have you stumbled onto a solution yet?Porbeagle
H
0

I think you should be looking in the System.Web.dll not System.Web.ApplicationServices.dll

Hf answered 18/5, 2012 at 10:18 Comment(3)
looking at this dll, I found that:Cheesecloth
are you not looking for System.Web.Security.Membership.GetAllUsers() ?... its in Membership, not SqlMembershipProvider.Hf
I can not access it via SqlMembershipProvider.Cheesecloth
T
0

The way it works is that you have to have your membership provider, like a SqlMembershipProvider, configured in your web.config. The Membership.GetAllUsers method will then take the default configured MembershipProvider and call its method GetAllUsers and pass in 0 for the current page index and int.MaxValue for the total records per page (as well as an out int to get the total records in the store).

If you are having issues calling this method check the following:

  • You have the correct .net assemblies referenced
    • System.Web
    • System.Web.ApplicationServices
    • System.Configuration
  • You have the correct namespace referenced System.Web.Security either
    • In your using statements at the top of the file
    • Directly on the type where referenced
  • Your web.config has a registered default MembershipProvider

Notes

  • SqlMembershipProvider, which derives from MembershipProvider, is not the same type or type hierarchy as type Membership. So not all the methods you see on Membership can be found on types deriving from MembershipProvider.
  • The type Membership is static and so all its members including Membership.GetAllUsers are static as well.
  • The type Membership is there as a convenience, most of its members call through to the registered default MembershipProvider.

Code sample:

using System.Web.Security;
namespace MyNameSpace
{
    public class MembershipTests
    {
        public void Test()
        {
            var users = Membership.GetAllUsers();
            // same as
            var totalRecords = 0;
            users = Membership.GetAllUsers(0, int.MaxValue, out totalRecords);
            // same as (Membership.Provider gets the default registered MembershipProvider)
            users = Membership.Provider.GetAllUsers(0, int.MaxValue, out totalRecords);
        }
    }
}

From the documentation

Remarks

GetAllUsers returns the information for all membership users for an application as a collection of MembershipUser objects. Be careful when using the GetAllUsers method with very large user databases, as the resulting MembershipUserCollection in your ASP.NET page may degrade the performance of your application.

Thrown answered 19/4, 2016 at 10:15 Comment(0)
D
0

The question is "Where is GetAllUsers in membership provider?"

The answer is that it is not in MembershipProvider. It is in System.Web.Security.Membership

The MSDN link you provided in your question says the same thing.

The method GetAllUsers static and overloaded.

int userCount = 0;
MembershipUserCollection muc1 =  System.Web.Security.Membership.GetAllUsers();
MembershipUserCollection muc2 = System.Web.Security.Membership.GetAllUsers(0, int.MaxValue, out userCount);

If you are having namespace issues, they shuffled some things around between .net 3.5 and .net 4.0

This bit me several years ago.

.Net 4.0 System.Web.Security.MembershipProvider ambiguous reference?

Dime answered 22/4, 2016 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.