Hide the PersonaBar from a Role in DNN
Posted in DNN on February 18, 2020
If you need to hide the PersonaBar in DNN 9+, you can use some simple CSS inside of your skin's .ascx file. Simply use some conditional code to detect the role of the user that's logged in and add some CSS inline to the page. Here's how you could do it:
- Open your skin file .ascx
- Add the following code:
<% If DotNetNuke.Security.PortalSecurity.IsInRole("Content Editors") Then %>
<style type="text/css">
#Body {
margin-left: 0;
}
.personalBarContainer {
display: none;
}
</style>
<% End If %>
- Notice on the first line I have "Content Editors" - this is the exact name of the DNN Role in my portal. If you have a different role, like "Admins" or "Translators", then change this line
- Save your file
- Test it out by logging in as a user in that role. It shouldn't be present
This is one of those your mileage may vary solutions. Here are the caveats:
- This only hides it through CSS but doesn't actually remove it from the source or improve the performance of the page
- The code only affects one role so you might need to modify it to support multiple roles
- This always matches if the user is in this role. So you might run into problems if the user belongs to multiple roles and one of those roles needs the PersonaBar.
This isn't a perfect solution by any means but it's definitely pretty easy and can help in a pinch. And the bonus is that this code isn't limited to CSS. You could put anything you want in there to customize the experience for a user in that role.
I hope that this code helps! If you're looking for more advanced skinning techniques, I would love to help you. Check out my page on expert DNN development.
Aaron Lopez
Founder & Lead Developer at Wolf X Machina