This documentation is archived and is not being maintained.

RoleGroup Class

Associates a content template in a LoginView control with one or more roles defined for the Web site. This class cannot be inherited.

System.Object
  System.Web.UI.WebControls.RoleGroup

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

'Declaration
Public NotInheritable Class RoleGroup

The RoleGroup type exposes the following members.

  NameDescription
Public methodRoleGroupInitializes a new instance of the RoleGroup class.
Top

  NameDescription
Public propertyContentTemplateGets or sets the content template associated with this role group.
Public propertyRolesGets or sets the roles associated with this role group.
Top

  NameDescription
Public methodContainsUserIndicates whether the specified user is a member of any of the roles in the role group.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a comma-separated list of the roles associated with this role group. (Overrides Object.ToString.)
Top

You can use the LoginView control to define a set of content templates that contain the content that is displayed to Web site users based on the role assigned by Web site administrators. The RoleGroup class is used by the LoginView control to associate a content template with a set of roles.

To dynamically assign a template to the role group, set the ContentTemplate property to a reference to an object that implements the ITemplate interface.

You must configure role management to use the RoleGroup class. For more information, see Understanding Role Management.

The following code example assigns a custom template to the ContentTemplate property.


<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Private Class CustomTemplate
        Implements ITemplate

        Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) _
            Implements System.Web.UI.ITemplate.InstantiateIn
            Dim ln As New LoginName
            Dim ls As New LoginStatus
            Dim lc As New Literal

            lc.Text = "<br />"
            ln.FormatString = "Welcome, {0}. This line is from the template."

            container.Controls.Add(ln)
            container.Controls.Add(lc)
            container.Controls.Add(ls)

        End Sub
    End Class

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim rg As New RoleGroup
        rg.ContentTemplate = New CustomTemplate
        Dim RoleList(1) As String
        RoleList(0) = "users"

        rg.Roles = RoleList

        Dim rgc As RoleGroupCollection = LoginView1.RoleGroups
        rgc.Add(rg)
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:LoginView id="LoginView1" runat="server">
                <AnonymousTemplate>
                    You are not logged in.<br />
                    <asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus>
                </AnonymousTemplate>
                <LoggedInTemplate>
                    You are logged in as
                    <asp:LoginName id="LoginName1" runat="server" />. This message is not from the template.<br />
                    <asp:LoginStatus id="Loginstatus2" runat="server"></asp:LoginStatus>
                </LoggedInTemplate>
            </asp:LoginView>
        </form>
    </body>
</html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: