具有两个提供程序的 ASP.NET 成员资格无法使用 GetAllUsers 方法

发布于 2024-08-22 05:30:18 字数 1628 浏览 8 评论 0 原文

我正在使用两个会员提供商。当我声明以下语句

Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers

时,它给了我这个错误消息。

Argument not specified for paramenter 'totalRecords' of 'Public MustOverride Function GetAllUsers(pageIndex as Integer, pageSize as Integer, ByRef totalRecords as Integer) As System.Web.Security.MembershipUserCollection'

然后,我添加了它的要求:

Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(1, 50, 100)

我没有得到任何回报。我调试了它,allUsers = Nothing。

  1. 上面的声明有什么问题?

  2. 在调用 Membership.Providers("MembershipRoleManager").GetAllUsers 时,我真的必须提供参数吗?

更新1

如果,我使用了下面的语句:

Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(0, 0, totalUser)

我收到此错误消息:

The pageSize must be greater than zero.
Parameter name: pageSize. 
[ArgumentException: The pageSize must be greater than zero.
Parameter name: pageSize]
   System.Web.Security.SqlMembershipProvider.GetAllUsers(Int32 pageIndex, Int32 pageSize, Int32& totalRecords) +1848357

但如果我提供了 pageSize 参数,它就会起作用:

Dim pageSize As Integer = GetTotalNumberOfUser()
Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(0, pageSize, totalUser)

此语句 Dim pageSize As Integer = GetTotalNumberOfUser() 返回总计数记录,它是已经往返数据库,只是为了获取用户总数,因为我需要提供 pageSize 参数值。

I'm using two membership providers. When I declared a following statement

Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers

Then, it gave me this error message.

Argument not specified for paramenter 'totalRecords' of 'Public MustOverride Function GetAllUsers(pageIndex as Integer, pageSize as Integer, ByRef totalRecords as Integer) As System.Web.Security.MembershipUserCollection'

Then, I added what it asked for like this :

Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(1, 50, 100)

I don't get anything in return. I debugged it and allUsers = Nothing.

  1. What's wrong the declaration above?

  2. Do I really have to provider the paramenters when calling Membership.Providers("MembershipRoleManager").GetAllUsers?

Update 1

If, I used the statement below:

Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(0, 0, totalUser)

I got this error message:

The pageSize must be greater than zero.
Parameter name: pageSize. 
[ArgumentException: The pageSize must be greater than zero.
Parameter name: pageSize]
   System.Web.Security.SqlMembershipProvider.GetAllUsers(Int32 pageIndex, Int32 pageSize, Int32& totalRecords) +1848357

But it works if I provied the pageSize param:

Dim pageSize As Integer = GetTotalNumberOfUser()
Dim allUsers As MembershipUserCollection = Membership.Providers("MembershipRoleManager").GetAllUsers(0, pageSize, totalUser)

This statment Dim pageSize As Integer = GetTotalNumberOfUser() returns the total counted record, it's already round trip to database, just to get the total number of users, because I need to provide the pageSize param value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星星的轨迹 2024-08-29 05:30:18

re #1 :totalRecords 是一个输出参数。

int totalRecords;
Membership.Providers["xxxx"].GetAllUsers(0, 10, out totalRecords);

VB

Dim totalRecords As Integer
Membership.Providers("xxxx").GetAllUsers(0, 10, totalRecords)

您使用totalRecords 来获取分页的记录计数,例如

#2:嗯,不,您不必提供参数值,除非您希望代码按预期方式运行。哈哈。我当然不会怀念我写VB的12年。

不过,说真的。是的,提供记录的参数,获取记录的结果。这就是它的工作原理。

来自MSDN

GetAllUsers返回的结果
受 pageIndex 和
页面大小参数。页面大小
参数标识最大值
MembershipUser 对象的数量
返回在
会员用户集合。这
pageIndex 参数标识了哪个
要返回的结果页,其中 0
标识第一页。这
TotalRecords 参数是一个输出
参数设置为总计
会员用户数
配置的应用程序名称。为了
例如,如果有 13 个用户
配置的applicationName,以及
pageIndex 值为 1,pageSize 为
5、MembershipUserCollection
返回将包含第六个
通过第十个用户返回。
TotalRecords 将设置为 13。

r.e. #1 : totalRecords is an out param.

int totalRecords;
Membership.Providers["xxxx"].GetAllUsers(0, 10, out totalRecords);

VB

Dim totalRecords As Integer
Membership.Providers("xxxx").GetAllUsers(0, 10, totalRecords)

You use totalRecords to get a record count for paging, e.g.

r.e. #2: umm, no, you don't have to provide parameter values unless you want the code to behave in an expected manner. lol. i sure do not miss the 12 years i spent writing vb.

seriously, though. yeah, supply parameters as documented, get results as documented. thats how it works.

From MSDN

The results returned by GetAllUsers
are constrained by the pageIndex and
pageSize parameters. The pageSize
parameter identifies the maximum
number of MembershipUser objects to
return in the
MembershipUserCollection. The
pageIndex parameter identifies which
page of results to return, where 0
identifies the first page. The
totalRecords parameter is an out
parameter that is set to the total
number of membership users for the
configured applicationName. For
example, if there are 13 users for the
configured applicationName, and the
pageIndex value was 1 with a pageSize
of 5, the MembershipUserCollection
returned would contain the sixth
through the tenth users returned.
totalRecords would be set to 13.

丿*梦醉红颜 2024-08-29 05:30:18

GetAllUsers(int, int, int) 的目的是用于对用户进行分页,因此您需要传递要开始的结果页、每页结果数,并且它将用记录总数填充第三个参数:

获取数据库中所有用户的数据页集合

GetAllUsers() 。 aspx" rel="nofollow noreferrer">以下警告

对非常大的用户数据库使用 GetAllUsers 方法时要小心,因为 ASP.NET 页面中生成的 MembershipUserCollection 可能会降低应用程序的性能。

但是,在您的问题中,您声明您正在使用两个不同的会员提供程序 - 您说使用 CustomSqlRoleManager 不会返回任何用户,而(大概)您正在从 MembershipRoleManager 返回结果。

您是否尝试过使用 MembershipRoleManager 调用 GetAllUsers()

是否有可能 CustomSqlRoleManager 背后的数据库目前没有任何用户?是否有可能 CustomSqlRoleManager 的命名并不糟糕,并且根本不处理成员,只处理角色?

GetAllUsers(int, int, int) is designed to be used to paginate through your users, so you need to pass the page of results you're starting on, the number of results per page, and it will fill the third parameter with the total number of records:

Gets a collection of all the users in the database in pages of data

GetAllUsers() comes with the following warning:

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.

However, in your question you state you are using two different Membership providers - you say that using CustomSqlRoleManager returns no users, while (presumably) you are getting results back from MembershipRoleManager.

Have you tried calling GetAllUsers() using the MembershipRoleManager?

Is it possible that the database behind CustomSqlRoleManager doesn't have any users in it at the moment? Is it possible that CustomSqlRoleManager isn't poorly named and doesn't deal with members at all, only roles?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文