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.0Programmatically Add User To RoleProgrammatically Add User To Role
Previous
 
Next
New Post
4/29/2008 1:07 AM
 

I have a module where I need to create user accounts programmatically.  I have successfully completed this step using AspNetMembershipProvider.CreateUser.  I have tried adding the user to the various roles using the roles property but cannot get it to work correctly.  My code is shown below:

mp As New DotNetNuke.Security.Membership.AspNetMembershipProvider

Dim

ui As New DotNetNuke.Entities.Users.UserInfo

Dim

ui.Roles = roles

mp.CreateUser(ui)

roles() As String = {"Registered Users", "Subscribers", "Flexistaff"}

 

Can someone point me in the right direction of how to add a user to an existing role.

Thanks.

Dim

 
New Post
4/29/2008 8:51 AM
Accepted Answer 

Linda:

Check this: 

RoleController.AddUserRole(PortalID, UserID, RoleID, ExpiryDate)

Edit: You can also do this to use the role name if you don't know the RoleID: 

RoleController.AddUserRole(PortalID, UserID, RoleController.GetRoleByName(PortalID, "RoleNameString").RoleID, ExpiryDate)

I think this is the more "proper" way.

Carlos

 

 
New Post
4/30/2008 1:20 AM
 

Hi Carlos,

 

Thanks for the response.  Worked perfectly I just couldn't locate the right class in the library. 

 

Thanks,

Linda

 
New Post
5/7/2008 11:32 PM
 

Carlos,

I have code that is similar to that which you posted and it worked GREAT in DNN3.  But then my site migrated to DNN4 and now this code SOMETIMES assigns users to the role and sometimes it doesn't.  I'm not sure what the issue is but Mitch Sellers worked on this module for a little bit and he said the issue was due to a bug in DotNetNuke.  Have you heard this?  Here is my code:

' Now give role access
Dim TheRoleName As String
Dim TheRoleID As Integer
If RequestInfo.InstructorPilot Then TheRoleName = "AF-IP"
If RequestInfo.StudentPilot Then TheRoleName = "UPTstud"
If (Not RequestInfo.InstructorPilot) And (Not RequestInfo.StudentPilot) Then TheRoleName = "AF-PilotSelect"
Dim RoleController As New DotNetNuke.Security.Roles.RoleController
Dim RoleInfo As New DotNetNuke.Security.Roles.RoleInfo
RoleInfo = RoleController.GetRoleByName(Me.PortalId, TheRoleName)
TheRoleID = RoleInfo.RoleID
RoleController.AddUserRole(Me.PortalId, OurUserID, TheRoleID, Null.NullDate)


I'm too poor for anything other than the community version
 
New Post
5/8/2008 2:39 PM
 

Carlos Rodriguez wrote

Linda:

Check this: 

RoleController.AddUserRole(PortalID, UserID, RoleID, ExpiryDate)

Edit: You can also do this to use the role name if you don't know the RoleID: 

RoleController.AddUserRole(PortalID, UserID, RoleController.GetRoleByName(PortalID, "RoleNameString").RoleID, ExpiryDate)

I think this is the more "proper" way.

Carlos

 

 

Where do I add this code?  I need to do the same thing programmatically.   Do I add it to the click event when the user selects the "Register" button?

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Programmatically Add User To RoleProgrammatically Add User To Role


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