RoleGroup Class
Collapse the table of content
Expand the table of content

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.

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


public sealed class RoleGroup


Initializes a new instance of the RoleGroup class.


Gets or sets the content template associated with this role group.


Gets or sets the roles associated with this role group.


Indicates whether the specified user is a member of any of the roles in the role group.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Returns a comma-separated list of the roles associated with this role group.(Overrides Object.ToString().)

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="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<script runat="server">
    private class CustomTemplate : ITemplate
        public void InstantiateIn(System.Web.UI.Control container)
            LoginName ln = new LoginName();
            LoginStatus ls = new LoginStatus();
            Literal lc = new Literal();

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


    void Page_Load(Object sender, EventArgs e)
        // <Snippet2>
        RoleGroup rg = new RoleGroup();
        rg.ContentTemplate = new CustomTemplate();
        // <Snippet3>
        String[] RoleList = {"users"};
        rg.Roles = RoleList;
        // </Snippet3>
        RoleGroupCollection rgc = LoginView1.RoleGroups;
        // </Snippet2>

<html xmlns="" >
    <head runat="server">
    <title>ASP.NET Example</title>
        <form id="form1" runat="server">
            <asp:LoginView id="LoginView1" runat="server">
                    You are not logged in.<br />
                    <asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus>
                    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>

.NET Framework
Available since 2.0

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

Return to top
© 2015 Microsoft