I have two applications, one is the main site and the other one is the administrative site.
The thing I want to do is remove users that belong to the main site, from the administrative, using Membership.DeleteUser
.
The problem is that it returns false, although Membership.GetUser
is returning me the correct user.
Microsoft documentation about DeleteUsers says
"Users deleted from the database are only deleted from the configured applicationName."
So there's nothing strange to my problem. I tried deleting a user that was created through my administrative application and it worked. But that's not what I want. Any ideas?
var muser = Membership.GetUser( userId, false );
if( !Membership.DeleteUser( muser.UserName, true ) )
{
throw new Exception( "An error occurred. User not deleted." );
}
I'm assuming you're using the default schema and implementation of Membership
. The providers (Membership
, Role
, etc.) all include an ApplicationName
property that is used, purposefully, to let you use one database for multiple applications but still have your users separated by app. As the documentation explains at http://msdn.microsoft.com/en-us/library/system.web.security.membership.applicationname%28v=vs.100%29.aspx, you need to programmatically change the ApplicationName
if you want to delete a user outside of the the current app.