开发者

ASP.NET Membership getuserbyID

开发者 https://www.devze.com 2023-04-03 07:07 出处:网络
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);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消