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

HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...programatically add to Roleprogramatically add to Role
Previous
 
Next
New Post
8/28/2008 10:11 AM
 

I have a situation where I need to add a new user to a role programatically.  Can someone please point me in the right direction of how to call the code to add uesr to a role.  We have a private portal and want to allow users to activate other users, as well as grant them access to the lowest level role.

Thanks.

 
New Post
8/28/2008 11:05 AM
 

DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();

rc.AddUserRole(portalId, userId, roleId, DateTime.MinValue); // add to user and never expire; optional overload takes two datetime values at the end, first is for effective date (to schedule in the future, for example) and second is the expiry date

Hope that helps. :)

*EDIT* Additionally you can call the AddUserRole static method (RoleController.AddUserRole(...)) which takes different (and more) parameters. 


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
8/28/2008 2:37 PM
 

I believe that I need to take the second approach, the one that calls DotNetNuke.Security.Roles.RollController.AddUserRole(objUser, objRole, PortalSetting, startdate, enddate, userID, notification as boolean).

How would I get the portalSettings?  I tried "Dim psettings As DotNetNuke.Entities.Portals.PortalSettings = PortalController.GetCurrentPortalSettings" and that seemed to work, but when I placed "psettings" as the 3rd parameter it is underlined and the message states "Named Argument Expected" when I hover over it.

Is there something I am missing, or maybe a different approach?

 
New Post
8/28/2008 3:27 PM
 

The only thing I wonder about is the "notification as boolean" you have there at the end.  VB isn't my strength, so maybe that is valid syntax, but in C# I'd expect to see it more like DotNetNuke.Security.Roles.RoleController.AddUserRole(objUser, objRole, this.PortalSettings, startDate, endDate, userID, notification); the "this.PortalSettings" (or Me.PortalSettings) would be if you are calling that directly from a module control that inherits from PortalModuleBase -- it'll have a reference to the PortalSettings automatically.  Otherwise your code to get the existing portalsettings *should* be fine.  At least, I tried that in C# and it worked fine.

Here is something that talks about the named parameters: http://msdn.microsoft.com/en-us/library/0t9f1e9s(VS.80).aspx but I looked at the code for that call and it doesn't look to me like it is expecting a specific name for the parameter.

BTW, for other readers -- the static call to the AddUserRole was added in one of the later versions (not present in 4.6.2); I'm not sure which version added the functionality, but it was at least some time after 4.6.2.


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
8/28/2008 4:48 PM
 

Thanks for the help!  i was able to get the job done.  I am a fairly new programmer so the error was me, your instructions were great.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...DNN Platform (o...DNN Platform (o...programatically add to Roleprogramatically add 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