Monday, May 10, 2010

Role Based Skinning

Similar to the "CSS Selectable Pages", we shall keep adding efficiency to our skin code. This time we have a look at ways to reveal or conceal parts of our skin to the users according to their role or authentication. For example we could have a common header image for our guests and a more particular one for our members. Or even a special one for the users in a specific role. You got the idea.
There are not much to explain actually. Instead, all we need is small pieces of server side code. The reason these techniques are not so known to the public is because they are not documented. I'm doing skins for several years and have been in situations where I had to find solutions that common skinning techniques don't make it. It's about those small code hints that really make a difference but we need to spend time to discover.

How to check whether a user is authenticated in skin code

<% if Request.IsAuthenticated then %>
 skin code for authenticated users
 <% end if %>
Real world example: On the PokerDIY web site we have a "Take a Tour" link in the header which becomes a link to your inbox once you are logged in.

How to check user's role in skin code

<% if UserController.GetCurrentUserInfo().IsInRole("Special Members") then %>
 skin code for registered users in the "Special Members" role
 <% end if %>
Real world example: On Seablick we replace the fancy header with a dynamic menu when logged in as Admin or Host.
I tried to give you some ideas but I'm sure you will find many other ways to use the above. I would love to read about your findings in the comments... Sometimes what seems to be obvious for you is well hidden for others.

No comments:

Post a Comment

MyUrduStuff

Search This Blog