Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

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!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Using PortalSecurity.IsInRoles doesnUsing PortalSecurity.IsInRoles doesn't always work
Previous
 
Next
New Post
4/28/2008 10:41 PM
 

Here's one that shows my ignorance of the code behind:

I often want to use this sort of thing to show or hide bits of a module's ascx file for different roles:

<% If DotNetNuke.Security.PortalSecurity.IsInRoles("role name") Then%>

Module Stuff

<%End If%>

However, I find that this code only works some of the time or only with some modules and some pages. 

It looks to me as if something has to be loaded up along with the file in order for this to work. Can anyone lead me in the right direction? Is there perhaps something I can include at the top of the file that will make it work?

Regards,
Rob

 
New Post
4/29/2008 5:59 AM
 

Rob,

I am not sure, I just checked the core code:

  • PortalSecurity.IsInRoles calls UserInfo.IsInRole
  • UserInfo.IsInRole checks the Roles property to contain the role name
  • Roles property autohydrates, if it has not already been populated

I have added Roles autohydration in DNN 4.7.0, previous DNN versions will not return the proper value, if not been explicitely loaded for the current user (which should be done by default). Please be aware, that role names are case sensitive. Can you be more specific, when the check is not executed properly?

 


Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
4/29/2008 9:41 PM
 

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

 

 
New Post
4/29/2008 10:16 PM
 

Rob,

I believe you're getting the error: "Code Blocks are not supported in this context", right?

I tried using this in some of the modules, but only several allowed the code. Others will throw that error.

I still haven't found the solution yet.

Duc

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Using PortalSecurity.IsInRoles doesnUsing PortalSecurity.IsInRoles doesn't always work


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out