simplemembership MVC4 get username by userId

。_饼干妹妹 提交于 2019-12-14 02:14:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!