سؤال

I need a list of "Approved" Users only, but don't know how to figure it out.

lstUsersNotInRole.DataSource = Membership.GetAllUsers(); // Get Approved Users Only!?!
lstUsersNotInRole.DataBind();

Any kind help would be highly appreciated.

Kardo

هل كانت مفيدة؟

المحلول

Instead of delving into the database and altering/creating stored procedures (and since you didn't specify which database you are using), you can do this by using Linq. Try this:

Membership.GetAllUsers().Cast<MembershipUser>().Where(u => u.IsApproved == true).ToList();

نصائح أخرى

You need to filter the approved users in your stored procedure and return the result to your application.

CREATE PROCEDURE dbo.Membership_GetActiveUsersInRoles

    @RoleName nvarchar(256)

AS

    BEGIN

        DECLARE @RoleId uniqueidentifier

        SELECT @RoleId = RoleId
        FROM dbo.aspnet_Roles
        WHERE LOWER(@RoleName) = LoweredRoleName

        SELECT u.UserName, u.UserId
        FROM dbo.aspnet_Users u, dbo.aspnet_UsersInRoles ur, dbo.aspnet_Membership m
        WHERE
        u.UserId = m.UserId AND
        u.UserId = ur.UserId AND
        @RoleId = ur.RoleId and
        m.IsApproved = 'true'
         -- You can also specify m.IsLockedOut = 'false' for other purposes

END

If you use the SqlMembershipProvider, you could select them manually, either as plain sql-statement(e.g. via ADO.NET) or by creating a custom stored-procedure which also supports paging and the ApplicationId and where you can parameterize IsApproved.

SELECT  m.IsApproved, u.UserName, 
        m.Email, m.PasswordQuestion, m.Comment, 
        m.CreateDate, m.LastLoginDate, u.LastActivityDate,
        m.LastPasswordChangedDate, u.UserId, 
        m.IsLockedOut, m.LastLockoutDate
FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u
WHERE  u.UserId = m.UserId 
AND    m.IsApproved = @IsApproved
ORDER BY u.UserName

Just have a look at dbo.aspnet_Membership_GetAllUsers, copy paste the relevant parts and modify it accordingly.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top