Need
DNN Support
?
DeskPal.com
Learn DNN / DotNetNuke
Login
Subscribe to DNNCreative
Home
Subscribe
Training & Tutorials
Tutorials for Beginners
Tutorials for Administrators
Tutorials for Core Modules
Tutorials for Advanced Users
How to Build a Website in DotNetNuke
Skinning Tutorials
Module Development
Third Party Modules
Forum
Search
Search
Home
Subscribe
+
Training & Tutorials
Tutorials for Beginners
Tutorials for Administrators
Tutorials for Core Modules
Tutorials for Advanced Users
How to Build a Website in DotNetNuke
Skinning Tutorials
Module Development
Third Party Modules
Forum
You need to
Register
for free and
Login
to post a message in the forum.
Forum
Forums
Search Forum
Search
Advanced Search
Topics
Posts
Unanswered
Active Topics
Forums
>
DotNetNuke®
>
DotNetNuke® Questions
AddUserToRole
Last Post 07/06/2010 6:16 PM by
Joseph Craig
. 3 Replies.
Sort:
Oldest First
Most Recent First
Check this box to subscribe to this topic.
Prev
Next
You are not authorized to post a reply.
Author
Messages
jbello
Nuke Newbie
Posts:5
04/26/2010 6:43 PM
I have been struggling with this all day. I need to create roles and add users to them through code. I can create roles but not add a user. When I try to add the user I get "The role '' was not found." This happens even if I hard code the role name in the function call. I tried searching the web for answers but did not find anything that seemed appropriate. The one thing that came up several times was an answer about configuring the roll provider in the web.config file. I'm not sure where that gets done or the correct syntax. I have a straight out of the box install of DNN with no manual changes to the existing web.config. I just don't understand how I can create a new role through code but then not add to it. If the proder was not configured then why can I create the role in the first place?
Joseph Craig
DNN MVP
Posts:11667
04/27/2010 6:38 PM
I've done something like this (c# version and without all of the necessary declarations):
uName = "joeuser";
oUserInfo = UserController.GetUserByName(PortalId, uName);
DotNetNuke.Security.Roles.RoleController rC = new DotNetNuke.Security.Roles.RoleController();
rC.AddUserRole(PortalId, oUserInfo.UserID, rC.GetRoleByName(PortalId, "roleName").RoleID, DateTime.Now,
DateTime.Now.AddYears(100));
This adds the username "joeuser" to the role "roleName" ...
Joe Craig,
Patapsco Research Group
Complete DNN Support
KTN
Nuke Newbie
Posts:1
07/06/2010 5:38 PM
Hi Joseph, I have an external application that's trying to add a user role to a DNN user. I'm running install version of DNN 05.04.01. Here's my code: var container = new DotNetNuke.ComponentModel.SimpleContainer("Test"); DotNetNuke.ComponentModel.ComponentFactory.Container = container; DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController(); rc.AddUserRole(0, UserID, roleID, DateTime.Now, DotNetNuke.Common.Utilities.Null.NullDate); I get an exception and so I downloaded the source code to trace it. The very first line of RoleController.AddUserRole is Dim objUser As UserInfo = UserController.GetUserById(PortalID, UserId) which does Return memberProvider.GetUser(portalId, userId) At this time, memberProvider is Nothing so I get the "Object reference not set to an instance of an object.". Am I supposed to do anything else to have this working? Thanks
Joseph Craig
DNN MVP
Posts:11667
07/06/2010 6:16 PM
I'm not sure about this. As it is an external application, it may need to be logged in or connected in some way.
I would ask this question also in the DotNetNuke forums. There are more developers over there.
Joe Craig,
Patapsco Research Group
Complete DNN Support
You are not authorized to post a reply.
Special Bonuses
--Subscriber Bonuses
--Readers Offers
Users Lounge
--Announcements
--DNN Creative Articles
--Everything Else
--Feedback, Suggestions and More
--Membership
--Site Review Please!
--Testimonials
--Podcasts
DotNetNuke®
--DotNetNuke® Questions
--Modules
--Modules - What's needed?
--Quick Tips
Hosting
--DotNetNuke® Hosting Providers
Skinning Toolkit
--Skinning Toolkit
UK DotNetNuke User Group
Forums
>
DotNetNuke®
>
DotNetNuke® Questions
Latest Forum Posts
Can you Run Xcode in Linux?
by Aman Singh
Can you Run Xcode in Linux?
Can you Run Xcode in Linux?
by Aman Singh
Can you Run Xcode in Linux?
Billed for subscription that was canceled
by Ryan
I was just billed for a subscription that was canc eled / inactivetive how do I get a refund for th
Meta Title and Meta Description are not showing properly
by DNN User
Hi, On my site the meta title and meta descriptions are not showing properly. It's showing the m
Search is not functioning properly
by DNN User
Site: https://www.prv-engineering.co.uk/search If I search any item only the 1st option under sea
Search is not functioning properly
by DNN User
Site: https://www.prv-engineering.co.uk/search If I search any item only the 1st option under sea
DNN Platform import site optio
by Melanie Weaver
Is it possible to import site template in DNN Platform 8.0? We have internal Evoq Content 8.1 tha
Events Module for DNN V5?
by Tugboat
Would anyone have a download link for the version 5.0.3 Events Module? Thanks!
"Ghost" TabID Number?
by Tugboat
Hi! I have a portal instance with multiple child portals and on one of the child portals, there i
RE: DNN Load Testing
by ayman sharkawy
Hi. Have you already implemented a site using the DNN . And how the performance of the site and its
Publish All Pages
by NSUOK
I'm using DNN Evoq Content Basic 8.2.0. When I make the HTML Pro module display on all pages, I h
Simpler profile needed in 9.2.2
by Donald
We are upgrading a DNN 4.8.4 site to DNN 9.2.2. On 4.8.4, the top bar shows the user’s name. If yo
How to link from dnnmodal popup to web site page?
by Donald
Hello all. I am using a dnnmodal.show popup. The popup works correctly, showing the content that I
RE: Document Collaboration
by Nick Davern
That feature would be super beneficial for our needs as well! Does anyone have an update as to if th
RE: DNN 9.2, how to set default theme?
by Andy Stephenson DNN Creative
you do that under "Manage/Themes". Note the highlight blue border around the default container and d
DNN 9.2, how to set default theme?
by Donald
Please disregard, found Manage Themes I cannot find how to set a default portal theme in DNN 9.2
RE: Looking for DataSprings Dynamic Forms
by Andy Stephenson DNN Creative
Your best chance would be to contact Chad Nash @ http://www.datasprings.com/
Looking for DataSprings Dynamic Forms
by Jakir HM
Looking for DataSprings Dynamic Forms 3.4 for DNN 4.x 5.x for my site (https://themasters2018s.com/)
RE: Help with Cycle Image Carousel not displaying images
by peter
I had the same problem with the Will Strohl Content Slider after upgrading to DNN 9.1 The above an
RE: Object reference not set to an instance of an object
by Andy Stephenson DNN Creative
Check this one might be useful: http://www.dnnsoftware.com/answers/im-tryin-to-move-my-site-to-pr
Used
By
Testimonials