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

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to create a roleHow to create a role
Previous
 
Next
New Post
5/5/2008 5:57 AM
 

Hi!

     I want to create a role then I write the follow code

            DotNetNuke.Security.Roles.RoleInfo studentRoleInfo = new DotNetNuke.Security.Roles.RoleInfo();
            studentRoleInfo.RoleName = "student";
            studentRoleInfo.IsPublic = false;
            studentRoleInfo.AutoAssignment = false;
            studentRoleInfo.PortalID = 0;
            studentRoleInfo.Description = "student";     
            bool resultRole = DotNetNuke.Security.Roles.RoleProvider.Instance().CreateRole(0, ref studentRoleInfo);

but that can't create the role "student",I don't know why.    

How to use the method "CreateRole"?

Thanks!

 
New Post
5/7/2008 11:15 PM
 

I have a similar question that might actually help you.  Here is how I used to add a user to a "Security Role" back in DNN3.  I migrated to DNN4, however, and now this piece of code SOMETIMES assigns the user to the role and SOMETIMES it doesn't.  I have heard this is an error with DotNetNuke but I'm not sure.  Does anybody know how to programmatically assign someone to a role all the time?  I'm considering putting in a LOOP after this to see if the user IS in the role and if NOT then assign them into the role AGAIN until they are.  I'd rather not code like that since it might end up in a weird loop but....  Here is my code that sometimes works and sometimes doesn't:

CAN ANYBODY TELL ME HOW TO POST CODE SAFELY ON HERE WITHOUT THE FORMAT GETTING SCREWED UP?  Like a [CODE] [/CODE] method?

 

 ' 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'm too poor for anything other than the community version
 
New Post
7/23/2008 6:52 AM
 

Hi,

 I have tried to solve the problem using createrole and addrole but it is ot working in 4.x... i dont know why.

So, i have tried to insert direct to database.. and it is working..

            cmd.CommandText = "INSERT INTO Roles (PortalID, RoleName, Description,IsPublic, AutoAssignment,BillingFrequency,BillingPeriod,TrialFrequency,TrialPeriod) VALUES (" + Me.PortalId.ToString + ",'" + ri.RoleName + "', '" + ri.Description.ToString + "', 0,0,'N',1,'N',1)"

            connection1.Open()
            cmd.ExecuteNonQuery()

----Thanks

Mohsin

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to create a roleHow to create a 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