DotNetNuke 检索给定 UserID 的 UserInfo
dotnetnuke 框架中是否有一些东西可以让我向它传递一个 userId,并且它将返回填充该 userId 详细信息的 UserInfo 对象。
如果不是,正常的做法是什么?
Is there somthing in the dotnetnuke framework which will allow me to pass it a userId and it would return the UserInfo object filled with details of that userId.
If not what would be the normal way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
试试这个(在带有 C# 的 DNN 5.x 中)
然后稍后使用 UserInfo...
Try this (in DNN 5.x with C#)
Then use the UserInfo later...
我使用了bdukes发布的方式,做了一点修改:PortalId可以从PortalSettings获取:
I used the way posted by bdukes with one modification: PortalId can be get from PortalSettings:
为了获取当前用户,从版本 7.3 开始,以上所有内容均已弃用。现在您需要通过
Instance
属性和GetCurrentUserInfo()
方法访问用户信息,即:因此您可以获得
UserId
作为所以:因此,给定一个用户 ID,您可以像这样获取用户的信息:
请注意,
PortalId
是 DNN 上下文提供的属性,因此您只需按上面的方式键入它即可。我希望这有帮助。
To get the current user, as of version 7.3 all of the above have been deprecated. Now you need to use access the user info via the
Instance
property and theGetCurrentUserInfo()
method, i.e.:Hence you could get the
UserId
as so:So, given a user id, you could get the user's info like this:
Note that
PortalId
is a property provided by the DNN context, so you can simply type it as above.I hope this helps.
我相信 DotNetNuke.Entities.Users.UserController 有一个方法 (GetUser) 可以做到这一点,如果您也有门户 ID。用户可以跨门户共享,因此(显然)有必要知道您请求其用户信息的门户,然后它们才能正确填充 UserInfo 对象。
如果您只有用户 ID 而没有门户 ID,我首先建议您看看是否也可以获得门户 ID。如果没有,您将需要访问数据库来获取您需要的内容。理想情况下,您将尽可能少地呆在那里(因为数据库不是有保证的 API)。因此,如果您只是执行快速查询来获取用户的门户 ID:
那么您可以使用 UserController.GetUser 来检索您需要的内容。
I believe that DotNetNuke.Entities.Users.UserController has a method (GetUser) that will do that, if you also have a portal ID. Users can be shared across portals, so it's (apparently) necessary to know the portal for which you're requesting the user information before they can properly fill the UserInfo object.
If you only have a user ID and no portal ID, I'd first suggest that you see if you can get a portal ID, too. If not, you'll need to go to the database to get what you need. Ideally, you'll be in there as little as you can be (since the database isn't a guaranteed API). So, if you just do a quick query to get a portal ID for the user:
You can then use UserController.GetUser to retrieve what you need.
不返回用户 ID 是什么问题
It's not return User ID what is the problem
如果您需要获取当前用户,那就更简单:
只需注释即可。
If you need to get the current user it's simpler:
Just a note.