UserController.GetUser(PortalId,UserId,true / false)和UserController.GetCurrentUserInfo()之间的区别是什么

时间:2010-06-11 02:38:12

标签: dotnetnuke

任何人都可以与我分享您对UserController.GetUser(PortalId *,UserId *,true / false)和UserController.GetCurrentUserInfo()之间区别的理解。我可以互换使用吗?

*前提是PortalId和UserId是PortalModuleBase的属性

感谢。

1 个答案:

答案 0 :(得分:2)

以下是您从当前版本5.4.2的源代码中引用的两种方法。从我所看到的,差异是 1)GetUser已弃用 2)GetUser似乎手动水合角色,笔记表明单个用户自动补充水分

这是旧方法

       ''' -----------------------------------------------------------------------------
    ''' <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

这是新方法

    ''' -----------------------------------------------------------------------------
    ''' <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

有什么帮助吗?

感谢

马克布林

爱尔兰

1987 BMW R80GS

相关问题