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!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.

Dynamically Change DotNetNuke Skins by Security Role

Personalized DotNetNuke Skins

There are all kinds of ways to make a skin (or design) in DotNetNuke react in a dynamic or personalized fashion, and it can be done in any number of ways.  To date, my favorite article on how to do this was written by Vassilis Terzopoulos (@thinkofdesign).  As his Hook Your DotNetNuke Skins blog post illustrates, a "user control" style skin allows you to use and reuse the DotNetNuke API in your skin design.  This has potentially limitless potential in customizing the user experience from a very high level across your entire site.


One of the many ways to provide a dynamic experience for your website visitors is to “personalize” their experience.  There are many examples of personalization out there, from the iGoogle approach, to targeting content based off of user activity.  No form of personalization is wrong, as long as it adds positive value to the experience that your website visitors have while visiting your site.

I am going to focus on something very specific in terms of personalization for this blog post.  I am going to talk about serving up a specific design to your visitors, based upon the security role (or group) that your visitor belongs to.

Did you know that DotNetNuke has a personalization engine in the API?  It is pretty impressive.  You should take a look and build something cool with it.  ;)

Background:  Loading Skins

There are a few different ways to dynamically or programmatically change the skin for a specific page load.  DotNetNuke will look first for an override value in the URL.  If  specific value is found, then DNN will load that skin and/or container on that page load.  Second, DNN will look in a local cookie to see if there is a skin being defined.  Finally, if the first two methods did not specify a skin to load, DNN will load the default skins defined by the page or site.  In the event that the skin doesn’t exist, the default skin that ships with DNN will be loaded. 

This is why it’s important to not delete the original skin package after installing.

Probably the best way to approach dynamically loading a skin based on security role would be to create a simple cookie using either a DotNetNuke module, or HttpModule.  Either way, you will be able to retrieve the user information, and based on the IsInSecurityRole() property, generate a cookie that will in effect load the desired skin.

The Code

This solution is dependent upon the skins in question already being installed, and knowing which security roles there are to use for this purpose.  I am simply going to provide you the starting point in this blog post by means of a code snippet.  It will be up to you to find a cool way to use this in your own solutions.

Basically, this solution requires that you have access to the current HttpContext object.  This object must have the context of the current web request, or be spoofing it.

The snippet of code below assumes that you want to assign the built-in DarkKnight homepage skin to an imaginary security role you've created called "My Security Role."  Also note that you can use the UserController.GetCurrentUserInfo() method to get the current user object – provided that your code has the current HttpContext.


' import DotNetNuke.Entities.Users 
If Not Me.UserInfo Is Nothing AndAlso Me.UserInfo.UserID > Null.NullInteger Then
    If Me.UserInfo.IsInRole("My Security Role") Then
        ' import System.Web.HttpCookie 
        Response.Cookies.Add(New HttpCookie("SkinSrc", "[G]Skins/DarkKnight/Home-Mega-Menu.ascx"))
        ' either assign another skin, or do nothing 
    End If
    ' either assign another skin, or do nothing 
End If


// using DotNetNuke.Entities.Users 
UserInfo oUser = UserController.GetCurrentUserInfo();
if (this.UserInfo != null && this.UserInfo.UserID > Null.NullInteger)
    if (this.UserInfo.IsInRole("My Security Role"))
        // import/using System.Web.HttpCookie 
        Response.Cookies.Add(new HttpCookie("SkinSrc", "[G]Skins/DarkKnight/Home-Mega-Menu.ascx"));
        // either assign another skin, or do nothing 
    // either assign another skin, or do nothing 

Keep in mind that the above are just your starting points.  You can set this up and write the production code any way that you’d like.  The string value of security role would be pulled from a setting of some kind in the UI, where you would have queried the security roles that are in production.  You would need defensive code that checks to make sure that the security role still exists (people can and will delete it). 

However, the point should be pretty clear to you.  You can define a user specific cookie that loads a skin that is specific to the user.  If you want, you can base this off of user profile properties and pretty much anything else your code has access to.

The [G] value references the path to skins that are installed in the Host directory.  Skins that are installed for a specific portal would use [L] instead.

If you want to do the same thing for a container, use a cookie named ContainerSrc instead of SkinSrc.

Now you have all of the information you need to be able to pull off some magic with the design and personalization on your DotNetNuke website.  The rest is up to you. 

With DNN… You’re only limited by your creativity.

This blog post is cross-posted from my personal blog site.


Jonathan Johnson
In case someone sees this but not your person blog post, the correct cookie is:

add _ , add portalid, remove .ascx:

Response.Cookies.Add(new HttpCookie("_SkinSrc" + PortalId, "[G]Skins/DarkKnight/Home-Mega-Menu"));
Jonathan Johnson Tuesday, August 26, 2014 2:45 PM (link)
Andrew Walker
Good Post - will (late to the party) -- Jonathan - thanks for the fix - I was running in some circles for a bit.
Andrew Walker Tuesday, October 14, 2014 10:29 AM (link)

Comment Form

Only registered users may post comments.


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Davies (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Timo Breumelhof (24)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out