SirRoland
SirRoland

Reputation: 195

ASP.NET Membership getuserbyID

How I can get User by ID? MembershipUser mu=Membership.GetUser("UserName"); But, I want get user by ID, but not by name.

Upvotes: 3

Views: 1893

Answers (4)

Tim Schmelter
Tim Schmelter

Reputation: 460028

If you are using(or inheriting from) the standard SqlMemberShipProvider you can use MembershipProvider.GetUser(providerUserKey, userIsOnline).

Where providerUserKey is the GUID and userIsOnline is a boolean that indicates whether the last-activity date/time stamp for the specified user should be updated or not.

http://msdn.microsoft.com/en-us/library/ms152128.aspx

Upvotes: 1

FiveTools
FiveTools

Reputation: 6030

MembershipUser u = Membership.GetUser(id);

This will work (expects object ProviderUserKey) - which is GUID by the default asp.net membership provider.

Upvotes: 4

this. __curious_geek
this. __curious_geek

Reputation: 43207

If you're using inbuilt MembershipProvider, then you'll have to write a helper method which will do the job for you and return a MembershipUser instance based on the Id to query.

If you're using your own custom MembershipProvider, in that case you can create a method overload for Membership.GetUser() which will take an Id and return a MembershipUser instance, However, you will need to cast the MembershipProvider default instance to the type of your custom MemberdhipProvider to gain the type-safe access

Upvotes: 1

fardjad
fardjad

Reputation: 20394

Since user names are unique, you can query your application database Users table to get the UserName for a specific UserID and pass the result to Membership.GetUser("UserName");

Upvotes: 1

Related Questions