是否可以使用会员用户 ID 检索用户个人资料?
使用 Asp.net 会员资格和个人资料提供者:
我可以使用会员用户 ID 而不是用户名来检索用户个人资料吗?
我问的原因是因为如果我有 UserID 而不是 Username,我将不得不编写以下两行代码
Dim MembershipUser As MembershipUser = Membership.GetUser("UserID")
Dim Profile As Profile = Profile.GetProfile(MembershipUser.UserName)
而不是:
Dim Profile As Profile = Profile.GetProfile("UserID")
这会影响性能吗?我的设计不好吗?我错过了什么吗?
请注意:我知道我可以使用以下代码检索当前登录的用户:HttpContext.Current.User.Identity.Name
Using the Asp.net Membership & Profile Providers:
Am I able to retrieve a user profile using their Membership UserID instead of their Username?
The reason I ask is because if I have the UserID and not the Username I would have to write the following two lines of code
Dim MembershipUser As MembershipUser = Membership.GetUser("UserID")
Dim Profile As Profile = Profile.GetProfile(MembershipUser.UserName)
Instead of:
Dim Profile As Profile = Profile.GetProfile("UserID")
Will this affect performance? Is my design bad? Am I missing something?
Please note: I am aware that I can retrieve the current logged in user using the following code: HttpContext.Current.User.Identity.Name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
会给你你想要的 UserId。为了在 ASP.NET 应用程序中简单起见,我通常会在用户登录时进入会话。
asp.net 成员资格表对每个应用程序都有唯一的用户名,并且由于可以在一个数据库中定义多个应用程序,因此也可以调用 Profile.GetProfile( string userName ) 从不同的应用程序返回配置文件。这就是为什么没有 GetProfile( userName ) 并且自己实现它是一个坏主意。
will give you the UserId that you're after. For simplicity in asp.net apps I normally stick in into session when user logs on.
The asp.net membership tables have unique username per application, and as it is possible to define multiple applications in one database it will also be possible for a call Profile.GetProfile( string userName ) to return a profile from different application. This is why there's no GetProfile( userName ) and it's a bad idea implementing it yourself.