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  |  

Affordable ASP.NET Hosting Service
  Ads  
Webhost4Life - $4.95 Windows Hosting
 


  Sponsors  

Meet Our Sponsors

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


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! (Pro...  programatically add to Role
Previous Previous
 
Next Next
New Post 8/28/2008 8:11 AM
Resolved
User is offline andym
9 posts
10th Ranked


programatically add to Role 

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 9:05 AM
User is offline Fooberichu
475 posts
www.seeleyware.com
8th Ranked


Re: programatically add to Role 
Modified By Fooberichu  on 8/28/2008 11:06:50 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. 


-- Fooberichu
http://www.seeleyware.com
 
New Post 8/28/2008 12:37 PM
User is offline andym
9 posts
10th Ranked


Re: programatically add to Role 

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 1:27 PM
User is offline Fooberichu
475 posts
www.seeleyware.com
8th Ranked


Re: programatically add to Role 

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.


-- Fooberichu
http://www.seeleyware.com
 
New Post 8/28/2008 2:48 PM
User is offline andym
9 posts
10th Ranked


Re: programatically add to Role 

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 Previous
 
Next Next
  Forum  General DotNetN...  Extend It! (Pro...  programatically add 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.

 


FREE Skins, Modules & Control Panel!
Choose how much you want to pay on our Skins, Modules, Containers and Control Panel - Starting from FREE!
www.dnngroup.com
Disgrafic
Diseño y creación de portales web dinámicos :: Desarrollo de módulos personalizados :: Soluciones a medida :: Imagen Corporativa :: Tu proveedor DNN en España
www.disgrafic.com
DM Analytics, LLC
DM Analytics, LLC provides software solutions that facilitate rapid development of independent or dependent datamarts and their associated web-based reporting.
www.dmanalytics.com

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