Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0BC30469: Reference to a non-shared member requires an object referenceBC30469: Reference to a non-shared member requires an object reference
Previous
 
Next
New Post
8/13/2008 11:02 AM
 

That code looks a lot better, I wasn't really sure what you were trying to do with the original code.

You're very close here.  When you call GetUserByName and GetRoleByName, you are getting a UserInfo and RoleInfo object, respectively.  You just need to go one step further and ask those objects what their ID is.  so, UserController.GetUserByName(0, UserName1).UserID and GetRoleByName(PortalSettings.PortalId, RoleName1).RoleID should be all that you need.

Hope that helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
8/13/2008 12:18 PM
 

Wonderful Brian, you are a life saver!

Now what about creating the role(s) if they dont already exist?

I tried:

If Roles.RoleExists(RoleName1) = False Then
                Roles.CreateRole(RoleName1)
            End If

I get the error:

A critical error has occurred.
Unable to connect to SQL Server database.

I dont beleve RoleExists is a DNN Method so how can I make this work, and how do I set the Roles.RoleInfo, Info (ServiceFee, BillingPeriod, RoleGroup, etc)

 
New Post
8/14/2008 11:02 AM
 

You'll have to create a new RoleInfo object and set it up with a name, portalId, and whatever else you know about the role.  Then call DotNetNuke.Security.Roles.RoleController().AddRole(), providing that RoleInfo object.

Hope it helps,


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
8/14/2008 2:33 PM
 

Protected Sub CreateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateButton.Click
            Dim objRoles As New RoleController
            Dim UserName1 As String = User.Text
            Dim RoleName As String = (NS.Text & "2")
            Dim userEmail As String = Membership.GetUser(UserName1).Email
            Dim userId As Integer = UserController.GetUserByName(0, UserName1).UserID
            Dim roleId As String = objRoles.GetRoleByName(PortalSettings.PortalId, RoleName).RoleID
            Dim objRoleInfo As New RoleInfo
            Dim objRoleController As DotNetNuke.Security.Roles.RoleController
            objRoleController = New DotNetNuke.Security.Roles.RoleController
            objRoleInfo.AutoAssignment = False
            objRoleInfo.BillingFrequency = "Month"
            objRoleInfo.BillingPeriod = 6
            objRoleInfo.Description = NS.Text & "2"
            objRoleInfo.IsPublic = False
            objRoleInfo.PortalID = 0
            objRoleInfo.RoleID = roleId
            objRoleInfo.RoleName = RoleName
            objRoleInfo.ServiceFee = "0.00"

            objRoleController.AddRole(objRoleInfo)
            objRoleController.AddUserRole(PortalSettings.PortalId, userId, roleId, Null.NullDate, Null.NullDate)

        End Sub

Causes the error:

 

A critical error has occurred.
Object reference not set to an instance of an object.

 

What does this mean?

 
New Post
8/14/2008 3:59 PM
 

Brian, I just realised two other problems.

1. How can I check is the role already exists before it tries to create it? Im assuming that can cause a problem if it tries to create something that is already there.

2. I need to be able to assign a RoleA to everyone in RoleB. I have been playing with GetUsersinRole but cannot get it to work. Is there a better way? How do I add this info to my code so that it adds each user to that role?

Any examples would be wonderful and I am still very new to DNN & vb

Thank you again very much!

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0BC30469: Reference to a non-shared member requires an object referenceBC30469: Reference to a non-shared member requires an object reference


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out