tags:

views:

93

answers:

1

Could anyone possibly share me your understanding on the difference between UserController.GetUser(PortalId*,UserId*, true/false) and UserController.GetCurrentUserInfo(). Can I use them interchangeably?

*Provided that PortalId and UserId are the properties of PortalModuleBase

Thanks.

+1  A: 

Hello Kthurein,

Here are the two methods that you are referring to from the source code of the current version 5.4.2. From what I can see, the diffs are 1) GetUser is Deprecated 2) GetUser appears to manually hydrate the roles, the notes suggest that single users are automatically hydrated

here is the old method

       ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' GetUser retrieves a User from the DataStore
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <param name="portalId">The Id of the Portal</param>
    ''' <param name="userId">The Id of the user being retrieved from the Data Store.</param>
    ''' <param name="isHydrated">A flag that determines whether the user is hydrated.</param>
    ''' <param name="hydrateRoles">A flag that instructs the method to automatically hydrate the roles</param>
    ''' <returns>The User as a UserInfo object</returns>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    <Obsolete("Deprecated in DNN 5.1. Not needed any longer for single users due to autohydration")> _
    Public Shared Function GetUser(ByVal portalId As Integer, ByVal userId As Integer, ByVal isHydrated As Boolean, ByVal hydrateRoles As Boolean) As UserInfo
        Dim user As UserInfo = GetUserById(portalId, userId)

        If hydrateRoles Then
            Dim controller As DotNetNuke.Security.Roles.RoleController = New DotNetNuke.Security.Roles.RoleController
            user.Roles = controller.GetRolesByUser(userId, portalId)
        End If

        Return user
    End Function

and here is the new method

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' Get the current UserInfo object
    ''' </summary>
    ''' <returns>The current UserInfo if authenticated, oherwise an empty user</returns>
    ''' <history>
    '''     [cnurse]    05/23/2005  Documented
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Shared Function GetCurrentUserInfo() As UserInfo

        If (HttpContext.Current Is Nothing) Then
            If Not (Thread.CurrentPrincipal.Identity.IsAuthenticated) Then
                Return New UserInfo
            Else
                Dim _portalSettings As PortalSettings = PortalController.GetCurrentPortalSettings
                If Not _portalSettings Is Nothing Then
                    Dim objUser As UserInfo = GetCachedUser(_portalSettings.PortalId, Thread.CurrentPrincipal.Identity.Name)
                    If Not objUser Is Nothing Then
                        Return objUser
                    Else
                        Return New UserInfo
                    End If
                Else
                    Return New UserInfo
                End If
            End If
        Else
            Dim objUser As UserInfo = CType(HttpContext.Current.Items("UserInfo"), UserInfo)
            If Not objUser Is Nothing Then
                Return objUser
            Else
                Return New UserInfo
            End If
        End If
    End Function

is that any help?

thanks

Mark Breen

Ireland

1987 BMW R80GS

Mark Breen
Hi Mark Breen,This is exactly what I'm looking for. Thanks a lot ...
Kthurein