DotNetNuke 检索给定 UserID 的 UserInfo

发布于 2024-08-02 08:30:24 字数 104 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

你是年少的欢喜 2024-08-09 08:30:24

试试这个(在带有 C# 的 DNN 5.x 中)

private UserInfo _currentUser =
                   DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

然后稍后使用 UserInfo...

int UserID = _currentUser.UserID

Try this (in DNN 5.x with C#)

private UserInfo _currentUser =
                   DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

Then use the UserInfo later...

int UserID = _currentUser.UserID
暮年 2024-08-09 08:30:24

我使用了bdukes发布的方式,做了一点修改:PortalId可以从PortalSettings获取:

DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUser(PortalSettings.PortalId, user_id, true);

I used the way posted by bdukes with one modification: PortalId can be get from PortalSettings:

DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUser(PortalSettings.PortalId, user_id, true);
空名 2024-08-09 08:30:24

为了获取当前用户,从版本 7.3 开始,以上所有内容均已弃用。现在您需要通过 Instance 属性和 GetCurrentUserInfo() 方法访问用户信息,即:

DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo()

因此您可以获得 UserId 作为所以:

DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo().UserID

因此,给定一个用户 ID,您可以像这样获取用户的信息:

UserController.GetUserById(PortalId,your_user_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 the GetCurrentUserInfo() method, i.e.:

DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo()

Hence you could get the UserId as so:

DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo().UserID

So, given a user id, you could get the user's info like this:

UserController.GetUserById(PortalId,your_user_id)

Note that PortalId is a property provided by the DNN context, so you can simply type it as above.

I hope this helps.

扛起拖把扫天下 2024-08-09 08:30:24

我相信 DotNetNuke.Entities.Users.UserController 有一个方法 (GetUser) 可以做到这一点,如果您也有门户 ID。用户可以跨门户共享,因此(显然)有必要知道您请求其用户信息的门户,然后它们才能正确填充 UserInfo 对象。

如果您只有用户 ID 而没有门户 ID,我首先建议您看看是否也可以获得门户 ID。如果没有,您将需要访问数据库来获取您需要的内容。理想情况下,您将尽可能少地呆在那里(因为数据库不是有保证的 API)。因此,如果您只是执行快速查询来获取用户的门户 ID:

SELECT PortalID From {databaseOwner}{objectQualifier}UserPortals WHERE UserID = @userId

那么您可以使用 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:

SELECT PortalID From {databaseOwner}{objectQualifier}UserPortals WHERE UserID = @userId

You can then use UserController.GetUser to retrieve what you need.

我不会写诗 2024-08-09 08:30:24

不返回用户 ID 是什么问题

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
response.write(nowUser)

It's not return User ID what is the problem

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
response.write(nowUser)
盗心人 2024-08-09 08:30:24

如果您需要获取当前用户,那就更简单:

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo

只需注释即可。

If you need to get the current user it's simpler:

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo

Just a note.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文