2013-03-11 68 views

回答

5

而不是深入研究數據庫和更改/創建存儲過程(因爲您沒有指定使用哪個數據庫),所以可以使用Linq來完成。試試這個:

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

感謝您的如此完美和簡單的答案:-) – Kardo 2013-03-11 09:31:11

0

您需要過濾批准的用戶在您的存儲過程,並將結果返回到應用程序。

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 
0

如果使用SqlMembershipProvider,你可以手動選擇,無論是作爲普通的SQL語句(例如,通過ADO.NET)或通過創建一個自定義的存儲過程也支持分頁和ApplicationId並在那裏你可以參數化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 

只要看看dbo.aspnet_Membership_GetAllUsers,複製粘貼相關部分並相應地修改它。