views:

541

answers:

2

I'm creating a user approval interface leveraging the .Net Membership class. I have a page that does a Membership.GetAllUsers(), and I spit the results to a datagrid. I filter them by MembershipUser.IsApproved.

My Issue is due to slowness I'm hitting while I GetAllUsers().

Since I don't need to pull down all of the users, but rather, say, all of the users with a CreateDate falling within a certain range, I'm wondering if there's a way to grab a subset based on date-range?

Wanted to Update for those in a similar situation:


UPDATE: So, I ended up actually not using the answer below.. Although, it does address the specific question properly. Anyhow, my real problem was, grabbing a subset of Users (i.e. those requiring "approval" - Since my Admin holds control of this (not the users)). My solution was to assign newly signedup users to an "awaitingapproval" role, then I was able to grab Roles.UsersInRole("awaitingapproval"), display those to the Admin with the ability to "approve" a user. Each approved user is then dropped from "awaitingapproval" and assigned to a new role.

+1  A: 

Although there are overloads for GetAllUsers() to return a subset of users based on index (i.e. one "page" of users at a time), there is nothing that you could use to base it on custom logic like this.

I would probably write a new class that inherits the base membership provider and add a new overload for GetAllUsers().

You can use Reflector to see the source code for System.Web.Security.SqlMembershipProvider's implementation of GetAllUsers() as a starting point.

womp
Would it be possible to put this in my Utils class, or would it need to be its own class?
madcolor
A: 

I would rather say that you could use Linq for querying values , but as I tried it I get an error.

users.AsQueryable()
-->Exception : source is not source is not IEnumerable

Instead of using this you can write a stored procedure which gets all users from database by your given creating date and go over from that result.
--> There is on which Membership automatically creates in SQL Database, just Modify aspnet_Membership_GetAllUsers Stored Procedure by your given parameters

SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
        m.CreateDate,
        m.LastLoginDate,
        u.LastActivityDate,
        m.LastPasswordChangedDate,
        u.UserId, m.IsLockedOut,
        m.LastLockoutDate
FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
WHERE  u.UserId = p.UserId AND u.UserId = m.UserId AND
       p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound AND
       m.CreateDate BETWEEN @pFirstDate AND @pSecondDate //Additional

ORDER BY u.UserName
Myra
Definitely a solution (and one I considered), however I think it would be more OOP and in line with my pattern to go with [womp].
madcolor