Saturday, August 9, 2008

Creating a Custom Role to Display the Admin Control Panel

In my last DotNetNuke skinning post at http://dotnetnuke-skin.blogspot.com/2008/08/positioning-admin-control-panel-in-dnn.html I discussed how to position your admin control panel when creating a custom dnn skin. By adding the control panel declaritively instead of letting the DotNetNuke framework place it automatically at the top, you are able to place it where you want and access it through server side or JavaScript code in the skin.

For this post, we will focus on how to create a custom role that controls which users have access to the control panel.

First, create a custom role for your portal. Let's call it "Control Panel Access".
Next, create a new user for testing called cptest.
Next, manage the roles for the user and add them to the Administrators and Control Panel Access roles.

Now, we'll add the following code to the top of the skin:

<script runat="server">
Private Sub module_load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
If Not DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().IsInRole("Control Panel Access") And Not DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo().IsSuperUser Then
ControlPanel.Visible = False
End If
End Sub
</script>
<div id="ControlPanel" runat="server" />


What's happening here is simple, our script checks the currently logged in user to see if the user is either in the "Control Panel Access" role that we setup at the beginning of the post or a Host user. If neither of those conditions are true, then the control panel is hidden.

Happy Nuking,

Ryan Morgan


Arrow Consulting & Design is a consulting firm based in West Palm Beach, Florida specializing in DotNetNuke, ASP.NET, SQL and WPF Development with a portfolio filled with local, national, government and global enterprise clients.

Case Studies: Click Here
Main Corporate Site: http://www.arrowdesigns.com/default.aspx?utm_source=blogspot
DotNetNuke Community Site: http://www.arrownuke.com/default.aspx?utm_source=blogspot
Consulting Inquiries: Click Here
Skin Design/Conversion: Click Here
DotNetNuke Portfolio: Click Here

3 comments:

Katie Palmer said...

Would it be possible to display a contentpane to unathenticated users? And hide it when an Administrator is logged in?

Unknown said...

Is it possible to create a custom Control Panels for a different roles?

Allan said...

The custom software development delhi at Acetetch take into account your long term business benefits without compromising on the quality aspect while at the same time maintaining the best practices of software development. We believe in building a long standing partnership with our valued clients by designing, developing, maintaining and improving software development services