ASP.NET 会员资格 getuserbyID
如何通过ID获取用户? MembershipUser mu=Membership.GetUser("用户名"); 但是,我想通过 ID 获取用户,而不是通过名称获取用户。
How I can get User by ID?
MembershipUser mu=Membership.GetUser("UserName");
But, I want get user by ID, but not by name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用(或继承)标准 SqlMemberShipProvider 您可以使用
MembershipProvider.GetUser(providerUserKey, userIsOnline)
。其中
providerUserKey
是 GUID,userIsOnline
是一个布尔值,指示是否应更新指定用户的上次活动日期/时间戳。http://msdn.microsoft.com/en-us/library/ms152128.aspx
If you are using(or inheriting from) the standard SqlMemberShipProvider you can use
MembershipProvider.GetUser(providerUserKey, userIsOnline)
.Where
providerUserKey
is the GUID anduserIsOnline
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
这将起作用(需要对象 ProviderUserKey) - 这是默认的 asp.net 成员资格提供程序的 GUID。
This will work (expects object ProviderUserKey) - which is GUID by the default asp.net membership provider.
由于用户名是唯一的,因此您可以查询应用程序数据库
Users
表以获取特定UserID
的UserName
并将结果传递给Membership.GetUser("用户名");
Since user names are unique, you can query your application database
Users
table to get theUserName
for a specificUserID
and pass the result toMembership.GetUser("UserName");
如果您使用内置的 MembershipProvider,那么您必须编写一个帮助器方法来为您完成这项工作,并根据要查询的 Id 返回一个 MembershipUser 实例。
如果您使用自己的自定义 MembershipProvider,在这种情况下,您可以为 Membership.GetUser() 创建一个方法重载,它将采用 Id 并返回 MembershipUser 实例,但是,您需要将 MembershipProvider 默认实例转换为类型您的自定义 MemberdhipProvider 以获得类型安全访问
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