Programmatic AddUserRole Error

Last post 05-04-2006 2:21 PM by CurlyFro. 2 replies.

Sort Posts:

  • Programmatic AddUserRole Error

    05-04-2006, 9:04 AM
    • Member
      525 point Member
    • kcabrams
    • Member since 11-30-2005, 7:25 PM
    • Washington, DC
    • Posts 132

    Hi I am integrating our existing web application so it can be implemented as modules in a DNN website.  Part of this means having a double login which I have figured out how to do.  I just create the DNN Users on the fly after the username/password has been validated by our application.  This creation only happens the first time the person signs in.  After that whenever they log in it checks the username pass on our member ablication and then progromatically logs you into DotNetNuke. 

    Now our application has permissions just like DNN so i duplicated the roles in dotnetnuke.  After i create the DNN user for the first time I add the roles programattically using the Subroutine

    Sub AddUserRole(PortalID, UserID, RoleID, ExpirationDate)

    The only problem is when i do it it give me this error: Object reference not set to an instance of an object.  However when I check the DNN UserRoles table the roles get added correctly so I'm not sure where the error would possibly  be coming from.

    The function code is below.  Please help.  Thank you.

    Public Sub AddUserRole(ByVal PortalID As Integer, ByVal UserId As Integer, ByVal RoleId As Integer, ByVal ExpiryDate As Date)

    Dim originalAppName As String = ""

    Dim objUserController As New UserController
    Dim objUser As UserInfo = objUserController.GetUser(PortalID, UserId)
    Dim objUserRole As UserRoleInfo = GetUserRole(PortalID, UserId, RoleId)
               
    If objUserRole Is Nothing Then
                    originalAppName = Common.Globals.GetApplicationName
                    Common.Globals.SetApplicationName(PortalID)
                    DataProvider.Instance().AddUserRole(PortalID, UserId, RoleId, ExpiryDate)
                    objUserRole = GetUserRole(PortalID, UserId, RoleId)
                    Try
                        AspNetSecurity.Roles.AddUserToRole(objUser.Membership.Username, objUserRole.RoleName)
                    Catch ex As Exception
                        'Reset the Application Name
                        Common.Globals.SetApplicationName(originalAppName)                End Try
                Else
                    DataProvider.Instance().UpdateUserRole(objUserRole.UserRoleID, ExpiryDate)
                    
     End If

    End Sub

    KC Abramson
    www.ORCradio.com
    Web Application Developer
    Integrated Software Solutions, Inc.

    When you're feeling down just remember.....the best things in life are someone else's.
  • Re: Programmatic AddUserRole Error

    05-04-2006, 1:15 PM
    • Member
      525 point Member
    • kcabrams
    • Member since 11-30-2005, 7:25 PM
    • Washington, DC
    • Posts 132

    False alarm.  I use a session string to store the current roles from my member application.  It was uknown to me that when you use Redim ArrayVar(X) that X is not the LENGTH of the array but the Upperbound (Length -1) of the array which to me is really stupid.  After doing some reading i learned that using redim in the first place is pretty amateur so i changed my ways.  And Viola...Perfection.

    KC Abramson
    www.ORCradio.com
    Web Application Developer
    Integrated Software Solutions, Inc.

    When you're feeling down just remember.....the best things in life are someone else's.
  • Re: Programmatic AddUserRole Error

    05-04-2006, 2:21 PM
    • Member
      410 point Member
    • CurlyFro
    • Member since 05-16-2003, 2:20 PM
    • Posts 92
    hey kcabrams,
    did you get my email message?


    thanks.

    -ty
Page 1 of 1 (3 items)