具有两个提供程序的 ASP.NET 成员资格无法使用 GetAllUsers 方法
我正在使用两个会员提供商。当我声明以下语句
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。
-
上面的声明有什么问题?
-
在调用 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 参数值。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
re #1 :totalRecords 是一个输出参数。
VB
您使用totalRecords 来获取分页的记录计数,例如
#2:嗯,不,您不必提供参数值,除非您希望代码按预期方式运行。哈哈。我当然不会怀念我写VB的12年。
不过,说真的。是的,提供记录的参数,获取记录的结果。这就是它的工作原理。
来自MSDN
r.e. #1 : totalRecords is an out param.
VB
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
GetAllUsers(int, int, int)
的目的是用于对用户进行分页,因此您需要传递要开始的结果页、每页结果数,并且它将用记录总数填充第三个参数:在 GetAllUsers() 。 aspx" rel="nofollow noreferrer">以下警告:
但是,在您的问题中,您声明您正在使用两个不同的会员提供程序 - 您说使用
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:GetAllUsers()
comes with the following warning: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 fromMembershipRoleManager
.Have you tried calling
GetAllUsers()
using theMembershipRoleManager
?Is it possible that the database behind
CustomSqlRoleManager
doesn't have any users in it at the moment? Is it possible thatCustomSqlRoleManager
isn't poorly named and doesn't deal with members at all, only roles?