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  |  

$4.95 Windows Hosting at Webhost4life.com
  Ads  
r2i.ntegrated
 


  Sponsors  

Meet Our Sponsors

Webhost4life, specialists in DNN hosting
Mad Development is a full service interactive agency focusing on the merge of design, technology, e-commerce, and affiliate marketing by providing total website solutions.
AspDotNetStoreFront - E-Commerce by Design - The Leading ASP.NET shopping cart platform for developers!
SteadyRain
DataSprings - Great Ideas. Always Flowing.
R2integrated - formerly bi4ce
 


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
467 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
467 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.

 


Adaptive InfoSystems, Inc.
We provide custom programming and various levels of support for DotNetNuke and the .Net framework.
www.aisysweb.com
Multipartner Virtual Data Rooms
The Virtual Data Rooms (VDR) provided by an expert advisor, far from any ordinary software company!, supporting the sellers and their consultants. Multipartner builds and services higly professional Virtual Data Rooms (VDR) specifically tailored to M&A, Real Estate and NPL deals.
www.multipartner.com
DNN SEO
Seablick Consulting specializes in DNN search engine optimization (SEO), DNN consulting, as well as support & training.
seablick.com

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