tags:

views:

555

answers:

4

Hi all,

I'm using DNN 5.x;I want to delete an user from C# code. The code I tested is:

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

Howver, the correponding record remains in tables: aspnet_users, aspnet_membership, users. What should I use to get full deletion?

Thanks.

+2  A: 

I don't believe they've implemented complete deletion in DNN 5.x yet (in DNN 4, they had full deletion, then moved to soft deletion in DNN 5). You may want to check the source code for that DeleteUser method in DNN 4.9.x or 4.8.x and see what it's doing (probably just a difference in what the stored procedure is doing). You should then be able to copy that stored procedure implementation and call it directly.

bdukes
http://www.dnndaily.com/tips/itemId/31941/How-to-Hard-Delete-users-in-DotNetNuke.aspx is a good post on how to hard delete users.
notandy
+1  A: 

I use the following SQL statements to delete a user. You can easily integrate that into .net code...

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;
Johannes
WHy @TablesToDeleteFrom is 15? why @NumTablesDeletedFrom =1? how did you set these values?
lmsasu
A: 

I hacked DeleteUserPortal sproc to hard delete users in 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
creator