Last post Mar 08, 2006 04:49 PM by NateDawg
Mar 08, 2006 12:36 AM|NateDawg|LINK
I’ve been searching the asp.net site for a while now and I have not found any posts regarding this but then again I might not be looking for the right thing. I’m developing a module and I need to be able to turn
parts of the module on and off based on what roles the currently logged on user is in. the roles need to be able to be specified by the admin from the settings page. Now I fully understand the permission for the module as a whole and that’s working fine. I’ll
try and describe as best as I can what I’m trying to do and what I have working so far.
On the main page there are three sections Part-A, Part-B and Part-C then in the admin site I need to have a corresponding Part-A, Part-B and Part-C then for each part I need a means to select from a list of all
the roles for that portal which one will be able to access that part. So Role-A can access all three parts Role-B can access only the last two parts etc. this needs to be possible in any combination. I would like it if the method of selection is ether a check
box list, or a dual list box control and is dynamic enough that if a new role is added after the development of the module the page will automatically adapt the new role onto the list.
I have done some poking around in the core and have found some bits of code that might come in handy. I don’t know if this is the best way to do what I need to do but it’s all I’ve got so far.
I have a custom DNN duel list control on the settings.ascx page called dlcEditUsers the following is the code from the settings.asx.vb page
As New DotNetNuke.Security.Roles.RoleController
As New DotNetNuke.Security.Roles.RoleInfo
As New System.Collections.ArrayList
Each Role In objRoles.GetPortalRoles(PortalId,
dlcEditUsers.Available = list
This works fine to put a list of all the roles into the dual list box but then I need a way to save the list of selected users and a way for the main module to retrieve this list. I had been using the following
method for storing settings from the admin page to be used on the main page.
As New DotNetNuke.Entities.Modules.ModuleController
This works well for strings and CTyped Booleans and integers, but when it comes to ArrayLists the waters get a little murky. So if I could find a good way to store the settings of the duel list control above and
access if from the main page I could then use part of the following code to some how programmatically control access.
Each Role In
'List of roles from settings page
Each User In objRoles.GetUsersInRole(PortalId, Role.RoleName)
If anyone has thought or ideas on this matter ether how to save and transmit the ArrayList, or just a different/better way to do this please let me know. I’d really appreciate any help I can get.
Thanks, Nathan Rover
Mar 08, 2006 07:40 AM|imagemaker|LINK
Mar 08, 2006 04:49 PM|NateDawg|LINK
I had been using comma delimited list to represent an array or object list collection. And for some reason it was not working. So, I went through today and made a library that had basic functions to convert and ArrayList and a ListItemCollection
to a semicolon delimited list and back again. This time I got it to work. The code that I used in my custom user control for selecting the roles was rather basic.
As New System.Collections.ArrayList()
Each Role In objRoles.GetPortalRoles(_PortalID,
dlcPickRoles.Available = BRAssociates.BRALIB.ArrListSubArrList(List, _ BRAssociates.BRALIB.String2ArrList(_Roles))
dlcPickRoles.Assigned = BRAssociates.BRALIB.String2ArrList(_Roles)
Then the code that I used in the main part of the program was rather simple too.
As Boolean =
If Settings("EditPermissInherit") =
As System.Collections.ArrayList = _ BRAssociates.BRALIB.String2ArrList(Settings("EditPermissValues"))
As Object = ArrayList.GetEnumerator
Each Item In ArrayList
Each User In objRoles.GetUsersInRole(PortalId, Item.ToString())
I thought this should be an easy thing to do, I don’t know why it took me the better part of two days to work out. Once again thanks for your help bill and if anyone reads through this code and knows of a better way to do this please let
me know… I’m always looking for ways to clean up my code.