RoleGroup Class
Assembly: System.Web (in system.web.dll)
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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."; container.Controls.Add(ln); container.Controls.Add(lc); container.Controls.Add(ls); } } void Page_Load(Object sender, EventArgs e) { RoleGroup rg = new RoleGroup(); rg.ContentTemplate = new CustomTemplate(); String[] RoleList = {"users"}; rg.Roles = RoleList; RoleGroupCollection rgc = LoginView1.RoleGroups; rgc.Add(rg); } </SCRIPT> <HTML> <BODY> <FORM 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>
- AspNetHostingPermission to run the RoleGroup control in a hosted environment. Associated enumeration: Minimal
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
RoleGroup MembersSystem.Web.UI.WebControls Namespace