Reputation: 204
I am trying to delete an asp.net user from all tables.
When I call:
bool isDeleted = Membership.DeleteUser(username, true);
isDeleted
is being set to false;
Is there a way to tell why it is not deleting the user?
Upvotes: 3
Views: 2759
Reputation: 21
I found another reason why the user could not be deleted:
it happens also if you change (in the aspnet_Users) the UserName
but not the LoweredUserName
accordingly.
At least this is what happened to me:
as soon that I changed also the LoweredUserName
I could finally delete the user.
Upvotes: 2
Reputation: 11
Unfortunately it looks like when you delete membership user, even with deleteAllRelatedData=true
e.g.
Membership.DeleteUser(UserName.Text, true);
The user is NOT deleted from the dbo.aspnet_Users table which means that user cannot then re-register with the same name again (even though they will will have a different GUID)
I understand this is intended behaviour though it makes no sense to me.
However, the following routine will remove all traces from the aspnet database
CREATE PROCEDURE [dbo].[ASPNET_Member_DELETE_By_Name]
@UserNameToDelete nvarchar(255)
AS
BEGIN
DECLARE @UserToDelete nvarchar(255)
SELECT @UserToDelete = UserID
FROM aspnet_Users WHERE UserName = @UserNameToDelete)
DELETE FROM aspnet_Profile WHERE UserID = @UserToDelete
DELETE FROM aspnet_UsersInRoles WHERE UserID = @UserToDelete
DELETE FROM aspnet_PersonalizationPerUser WHERE UserID = @UserToDelete
DELETE FROM aspnet_Membership WHERE UserID = @UserToDelete
DELETE FROM aspnet_Users WHERE UserID = @UserToDelete
END
However, this has limitations if you are using aspnet membership across several applications (as I am) with the same database - you may have a situation where the same user logs in to multiple applicatiosn with the same user name.
For this scenerio you will need to pass in the application name and determine the application ID for the user prior to performing the delete.
First time I've posted here so be gentle...
Upvotes: 1
Reputation: 1
Try removing the provider name, it worked for me by sending the username only.
I'm using SharePoint 3.0 with FBA, when a user is removed from SharePoint you can still find it in the FBA database. That's why I use this function as followed:
bool deleteUserResult = Membership.DeleteUser(currentUserLogin, true); if (!deleteUserResult) throw new Exception("...);
hope this helps, Damien
Upvotes: 0
Reputation: 16680
The username is probably wrong - either the name doesn't match what's in the database, or the user isn't really in the database.
However, the ApplicationName could be wrong, or you could be pointed at the wrong Membership database by mistake.
The only other possibility that I can see is that you've modified the aspnet_Users_DeleteUser sproc and broke it.
Upvotes: 0
Reputation: 9193
Put a break point on that line of code and press F8 to step into it in debug mode.
Upvotes: 1