Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

  Need Help?  
Professional technical support for DotNetNuke is available from DotNetNuke Corporation.
 


  Ads  
Indoo
 


  Sponsors  

Meet Our Sponsors

SmarterTools
The Official Microsoft ASP.NET Website
Portal Webhosting - Hosting For Developers
Red-Gate Software
MaximumASP
SourceGear - Tools for Developers
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  Programmatically Add User To Role
Previous Previous
 
Next Next
New Post 4/28/2008 10:07 PM
Resolved
User is offline Linda Wienholt
4 posts
10th Ranked


Programmatically Add User To Role 

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 5:51 AM
Accepted Answer 
User is offline Carlos Rodriguez
490 posts
www.almacigo.com
8th Ranked


Re: Programmatically Add User To Role 
Modified By Carlos Rodriguez  on 4/29/2008 8:57:52 AM)

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/29/2008 10:20 PM
User is offline Linda Wienholt
4 posts
10th Ranked


Re: Programmatically Add User To Role 

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 8:32 PM
User is offline Ryno
275 posts
9th Ranked




Re: Programmatically Add User To Role 

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 use DNN version 4.8.1
 
New Post 5/8/2008 11:39 AM
User is offline Maguire
1 posts
10th Ranked


Re: Programmatically Add User To Role 

 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 Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  Programmatically Add User To Role
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, 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 DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Module Development by Engage Software
Specializing in custom module development, training and skinning.
www.engagesoftware.com
BataviaSoft DotNetNuke Solutions
BataviaSoft offers custom DotNetNuke solutions especially for the European and the South East Asian market.
www.bataviasoft.com
Viva Portals, L.L.C.
Expert module development and graphic design.
www.continure.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP