Search code examples
c#asp.net-mvc-4membershipsimplemembership

simplemembership MVC4 get username by userId


Someone who works with MVC4 and the SIMPLEMEMBERSHIP knows how can I get a username by the userId? The user is not logged in and I want to delete it, and to delete I have to use

Membership.DeleteUser(string username)

Solution

  • You could use the GetUserNameFromId method of the SimpleMembershipProvider as such:

    SimpleMembershipProvider provider = new SimpleMembershipProvider();
    string name = provider.GetUserNameFromId(id);
    

    Ensure you have a reference to WebMatrix.WebData so you can use the SimpleMembershipProvider.