views:

221

answers:

2

Hi,

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.

+1  A: 

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.

Sky Sanders
Thanks for the input. Please see the update One in the question above.
Angkor Wat
@Bayonian, yes, sorry, typed that answer off the top of my head. You do need to provide a page size and to get a count you do need to make a pass at the db. Call GetAllUsers(0,1,totalRecords) to get a cheap count. As far as the cost goes, an operation like this should not be a part of each and every page lifecycle so the cost should be bearable.
Sky Sanders
A: 

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?

Zhaph - Ben Duguid
Thanks for the tip about the performance. Anyway,I just fixed my web.config. It was the problem with the typo.
Angkor Wat