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?

4

3 回答 3

0

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

于 2012-05-18T10:18:50.883 回答
0

问题是“会员提供商中的 GetAllUsers 在哪里?”

答案是它不在 MembershipProvider 中。它在 System.Web.Security.Membership 中

您在问题中提供的 MSDN 链接也说了同样的话。

GetAllUsers 方法静态且重载。

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

如果您遇到命名空间问题,他们会在 .net 3.5 和 .net 4.0 之间调整一些内容

几年前这让我很伤心。

.Net 4.0 System.Web.Security.MembershipProvider 不明确的参考?

于 2016-04-22T17:51:08.200 回答
0

它的工作方式是您必须您的web.config. 然后,Membership.GetAllUsers方法将采用默认配置MembershipProvider并调用其方法GetAllUsers并传入0当前页面索引和每页int.MaxValue的总记录(以及out int获取存储中的总记录)。

如果您在调用此方法时遇到问题,请检查以下内容:

  • 您引用了正确的 .net 程序集
    • System.Web
    • System.Web.ApplicationServices
    • System.Configuration
  • System.Web.Security您引用了 正确的命名空间
    • using文件顶部的陈述中
    • 直接在引用的类型上
  • web.config有一个注册的默认值MembershipProvider

笔记

  • 派生自的SqlMembershipProviderMembershipProvider与 type 不是同一类型或类型层次结构Membership。因此,并非您看到的所有方法Membership都可以在派生自MembershipProvider.
  • 该类型Membership是静态的,因此包括Membership.GetAllUsers在内的所有成员也是静态的。
  • 该类型Membership是为了方便起见,它的大多数成员都会调用已注册的 default MembershipProvider

代码示例:

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);
        }
    }
}

从文档

评论

GetAllUsers 将应用程序的所有成员用户的信息作为 MembershipUser 对象的集合返回。对非常大的用户数据库使用 GetAllUsers 方法时要小心,因为 ASP.NET 页面中生成的 MembershipUserCollection 可能会降低应用程序的性能。

于 2016-04-19T10:15:35.120 回答