在dotnetnuke中以编程方式删除用户

时间:2010-01-09 20:58:32

标签: api dotnetnuke

我正在使用DNN 5.x;我想从C#代码中删除用户。我测试的代码是:

UserInfo objUserInfo = DotNetNuke.Entities.Users.UserController.GetUser(0, userid, false);
UserController.DeleteUser(ref objUserInfo, false, false);

然而,相应的记录保留在表格中:aspnet_users,aspnet_membership,users。我应该用什么来完全删除?

4 个答案:

答案 0 :(得分:3)

调用DeleteUser后使用UserController.RemoveUser(objUserInfo)。所以你的代码看起来应该是

UserInfo objUserInfo = DotNetNuke.Entities.Users.UserController.GetUser(0, userid, false);
UserController.DeleteUser(ref objUserInfo, false, false);
UserController.RemoveUser(objUserInfo);

答案 1 :(得分:2)

我不相信他们已经在DNN 5.x中实现了完全删除(在DNN 4中,他们已完全删除,然后在DNN 5中转移到软删除)。您可能想要检查DNN 4.9.x或4.8.x中该DeleteUser方法的源代码,看看它正在做什么(可能只是存储过程正在做什么的差异)。然后,您应该能够复制该存储过程实现并直接调用它。

答案 2 :(得分:1)

我使用以下SQL语句删除用户。您可以轻松地将其集成到.net代码中......

DECLARE @NumTablesDeletedFrom int; 
DECLARE @userid INT;

EXECUTE [aspnet_Users_DeleteUser] @ApplicationName = 'DotNetNuke', @UserName = 'testUser', @TablesToDeleteFrom = 15, @NumTablesDeletedFrom = 1; 

SELECT @userid = UserID from users where Lower(username) = 'testUser'; 
EXECUTE [DeleteUser] @userid;

答案 3 :(得分:0)

我将HackUserPortal sproc攻击到DNN5.02.03中的硬删除用户

ALTER PROCEDURE [dbo].[DeleteUserPortal] 
    @UserID     int,
    @PortalID   int
AS
    IF @PortalID IS NULL
        BEGIN
            UPDATE dbo.Users
                SET
                    IsDeleted = 1
                WHERE  UserId = @UserID
        END
    ELSE
        BEGIN
            UPDATE dbo.UserPortals
                SET
                    IsDeleted = 1
                WHERE  UserId = @UserID
                    AND PortalId = @PortalID
        END

-- Custom modification to delete user records from db instead of soft delete
-- Code above is redundant

DECLARE @userName nvarchar(100)
DECLARE @aspnetUserId uniqueidentifier

SELECT @userName = username FROM dbo.Users WHERE UserId = @UserID
SELECT @aspnetUserId = UserId FROM dbo.aspnet_Users WHERE UserName = @userName

DELETE FROM Users WHERE UserId = @UserID
DELETE FROM aspnet_Membership WHERE UserId = @aspnetUserId
DELETE FROM aspnet_Users WHERE UserId = @aspnetUserId