Reputation: 1466
I have a membershipusercollection that I am trying to get one specific user from. Unfortunately I cannot user the MembershipUser.GetUser()
method. So currently I have a collection of all membership users like so:
MembershipUserCollection mc = Membership.GetAllUsers();
What I would like to do is get one of these users by either login or email (doesn't matter which). I realize I can do a foreach loop on the collection and compare but I have to imagine there is a better way....
Thanks in advance...
For those curious why I cannot user the getuser method, lets just say it is because of sharepoint.
Upvotes: 1
Views: 933
Reputation: 62260
MembershipUser.GetUser()
is not a valid method instead Membership.GetUser("johndoe")
.
var user = Membership.GetAllUsers()
.Cast<MembershipUser>()
.FirstOrDefault(m => m.Email == "[email protected]" || m.UserName == "johndoe");
One thing you want to watch out is GetAllUsers
retrieves all users from database.
Upvotes: 1
Reputation: 1466
Apparently there is another way:
MembershipUser m = mc["username"];
Upvotes: 0
Reputation: 1159
Try this
mc.Cast<MembershipUser>().SingleOrDefault(m => m.UserName == "username");
Upvotes: 2