 |
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 11th, 2010, 12:04 PM
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
asp:RoleGroup: Only pulls first rolegroup in list
I have a very simple page that displays a link for each rolegroup that a member belongs to with ASP.NET membership, lets say Group1 and Group2. For some reason, I can only see the first of two links in a list, regardless of which group it is.
I've already verified that both groups are pulling in fine by moving the Group2 link above Group1 to see if it could be viewed: which it was!
If Group1 is listed above Group 2, I see the link to Group1. But if I move the link for Group2 above Group1, I see the Group 2 link. I don't have a bunch of snazzy-dazzy complicated code on this page, so I'm stumped. Why could this be happening? I'd appreciate any help. Here is my code:
groups.aspx.vb
Code:
Partial Class groups
Inherits System.Web.UI.Page
'Pull username
Dim strLoginUserID As String = Context.User.Identity.Name
End Class
groups.aspx
Code:
<%@ Page Language="VB" title="List of Groups" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" EnableSessionState="true" EnableViewState="false" CodeFile="groups.aspx.vb" Inherits="groups" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Group1">
<ContentTemplate>
You are a member of group 1: <asp:HyperLink ID="hlGroup1" NavigateUrl="group1.aspx" runat="server">Group1</asp:HyperLink>
</ContentTemplate>
</asp:RoleGroup>
<asp:RoleGroup Roles="Group2">
<ContentTemplate>
You are a member of group 2: <asp:HyperLink ID="hlGroup2" NavigateUrl="group2.aspx" runat="server">Group2</asp:HyperLink>
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
</asp:Content>
|

January 11th, 2010, 12:43 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
The LoginView only displays content for the *first* matched RoleGroup, not for all matching groups:
http://msdn.microsoft.com/en-us/libr...olegroups.aspx
Quote:
The first matching role-group template is displayed to the user. If a user is a member of more than one role, the first role-group template that matches any of the user's roles is used. If more than one template is associated with a single role, only the first defined template will be used.
|
Cheers,
Imar
|

January 11th, 2010, 12:45 PM
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Wow, thanks for the quick reply.
That's a real bummer. Do you have any suggestions of alternative ways of doing the same thing?
|

January 11th, 2010, 12:51 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You could, if your model allows for it, repeat stuff from Group 1 in Group 2, and place Group2 as the first group. Alternatively, you could use Panel / Placeholder controls and manage the security from Code Behind....
Imar
|

January 11th, 2010, 01:03 PM
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Those are both good ideas. Inspired by your ideas, I'm thinking of dynamically handling the links on the code-behind (show/hide) depending on their roles using the User.IsInRole method, kinda like this:
If User.IsInRole("Group1") Then
hlGroup1.Visible = True
ElseIf If User.IsInRole("Group2") Then
hlGroup2.Visible = True
End If
Thanks for your help Imar!
|

January 11th, 2010, 01:09 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Code:
If User.IsInRole("Group1") Then
hlGroup1.Visible = True
ElseIf If User.IsInRole("Group2") Then
hlGroup2.Visible = True
End If
Funny, this is exactly the way the Login View does it. When you're in Group1, hlGroup1 is visible; otherwise hlGroup2 is ;-)
Imar
|

January 11th, 2010, 01:32 PM
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That is true, but we have an interesting scenario because this page is on our intranet, so every user is technically logged in. So users in the LoggedInTemplate see a message about them not being a member, while users who are members of a group will see links to their respective group.
So that's why I'm needing to go the extra step on this page. Thanks.
|

January 11th, 2010, 04:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I see, but that should be doable with just the LoginView? I thought you wanted to show Panel1 and Panel2 to users in Group2 in which case you need this code, don't you:
Code:
If User.IsInRole("Group1") Then
hlGroup1.Visible = True
End If
If User.IsInRole("Group2") Then
hlGroup2.Visible = True
End If
This way, if you're in both groups you see both panels.
But maybe i misunderstood....
Imar
|
|
 |