Thanks for looking at this Sebastian.
I'm a complete hack when it comes to this sort of thing. All I do with this is surround various sections of ASCX with that code - or variations there-of. This then will either hide or show that section of ASCX depending on the role I'm using.
<% If DotNetNuke.Security.PortalSecurity.IsInRoles("Administrator") Then%>
Stuff to hide from non-administrator
<%End If%>
I have found that this works fine in some cases but in others it causes a page load exception. For example, I've hidden large sections of the Active Forums control panel from non-admins because they should not be setting up things like caching or db file storage or even the html editor. This works very well and provides granular control where module developers have not.
This works fine in the HTML editor module EditHtml.ascx:
<% If DotNetNuke.Security.PortalSecurity.IsInRoles("Administrator") Or DotNetNuke.Security.PortalSecurity.IsInRoles("Webmaster") Then%>
<tr>
<td class="SubHead"><dnn:label id="plDesktopSummary" runat="server" controlname="txtDesktopSummary" suffix=":"></dnn:label></td>
</tr>
<tr>
<td><asp:textbox id="txtDesktopSummary" runat="server" textmode="multiline" rows="10" width="100%" columns="75" cssclass="NormalTextBox"></asp:textbox></td>
</tr>
<%End If%>
But the exact same thing does not work when I do it in some other modules. This example is in a Gumbosoft paypal module:
<% If DotNetNuke.Security.PortalSecurity.IsInRoles("Administrator") Or DotNetNuke.Security.PortalSecurity.IsInRoles("Webmaster") Then%>
<tr>
<td class="SubHead" valign="top" style="width:200px"><dnn:Label id="labelForceRegistration" runat="server" controlname="checkboxForceRegistration"></dnn:Label></td>
<td valign="bottom" >
<asp:CheckBox ID="checkboxForceRegistration" runat="server" CssClass="Normal" resourceKey="checkboxForceRegistration" AutoPostBack="true" OnCheckedChanged="checkboxForceRegistration_CheckedChanged" />
</td>
</tr>
<tr>
<td class="SubHead" valign="top" style="width:200px"><dnn:Label id="labelRoleToAdd" runat="server" controlname="dropDownRoleToAdd"></dnn:Label></td>
<td valign="bottom" >
<asp:DropDownList ID="dropDownRoleToAdd" runat="server" CssClass="Normal" Width="200px">
</asp:DropDownList><br />
</td>
</tr>
<%End If%>
That particular example results in a compile error.
I can't tell what the difference is... why it works in some places but not in others.
Any ideas are much appreciated
Rob