ASP.NET Membership getuserbyID
How I can get开发者_StackOverflow User by ID? MembershipUser mu=Membership.GetUser("UserName"); But, I want get user by ID, but not by name.
MembershipUser u = Membership.GetUser(id);
This will work (expects object ProviderUserKey) - which is GUID by the default asp.net membership provider.
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");
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
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
精彩评论