4

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?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
shad
  • 131
  • 2
  • 4
  • 9

6 Answers6

7

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
sth
  • 222,467
  • 53
  • 283
  • 367
user434247
  • 71
  • 1
  • 1
5

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);
Nico
  • 51
  • 1
  • 2
3

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.

Hugo Nava Kopp
  • 2,906
  • 2
  • 23
  • 41
2

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.

bdukes
  • 152,002
  • 23
  • 148
  • 175
2

It's not return User ID what is the problem

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
response.write(nowUser)
sth
  • 222,467
  • 53
  • 283
  • 367
uttam
  • 1
  • 1
1

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

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

Just a note.

sth
  • 222,467
  • 53
  • 283
  • 367
braindice
  • 988
  • 5
  • 16