问题
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)
回答1:
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
.
回答2:
SimpleMembershipProvider provider = (SimpleMembershipProvider)Membership.Provider;
string username= provider.GetUserNameFromId(12345);
//12345 is the id in SM UserProfile db table
来源:https://stackoverflow.com/questions/15192660/simplemembership-mvc4-get-username-by-userid