Share via


LoginView.RoleGroups 屬性

定義

取得將內容樣板與特定角色建立關聯的角色群組集合。

public:
 virtual property System::Web::UI::WebControls::RoleGroupCollection ^ RoleGroups { System::Web::UI::WebControls::RoleGroupCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.Themeable(false)]
public virtual System.Web.UI.WebControls.RoleGroupCollection RoleGroups { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.Themeable(false)>]
member this.RoleGroups : System.Web.UI.WebControls.RoleGroupCollection
Public Overridable ReadOnly Property RoleGroups As RoleGroupCollection

屬性值

RoleGroupCollection 物件,含有已定義的角色群組樣板。

屬性

範例

下列程式碼範例示範如何使用 RoleGroups 集合。 AnonymousTemplate由於 未設定 和 LoggedInTemplate 屬性,因此只會對屬於具有已定義內容範本角色的使用者顯示內容。

<%@ 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">
</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">
                <RoleGroups>
                    <asp:RoleGroup Roles="author">
                        <ContentTemplate>
                            <ul>
                                <li>Add a new article.</li>
                                <li>Review editorial changes.</li>
                                <li>View article requests.</li>
                            </ul>
                        </ContentTemplate>
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="editor">
                        <ContentTemplate>
                            <ul>
                                <li>Review articles.</li>
                                <li>Submit edited article.</li>
                            </ul>
                        </ContentTemplate>
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="publisher">
                        <ContentTemplate>
                            <ul>
                                <li>Make article request.</li>
                                <li>Publish reviewed article.</li>
                            </ul>
                        </ContentTemplate>
                    </asp:RoleGroup>
                </RoleGroups>
            </asp:LoginView>
        </form>
    </body>
</html>
<%@ 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">
</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">
                <RoleGroups>
                    <asp:RoleGroup Roles="author">
                        <ContentTemplate>
                            <ul>
                                <li>Add a new article.</li>
                                <li>Review editorial changes.</li>
                                <li>View article requests.</li>
                            </ul>
                        </ContentTemplate>
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="editor">
                        <ContentTemplate>
                            <ul>
                                <li>Review articles.</li>
                                <li>Submit edited article.</li>
                            </ul>
                        </ContentTemplate>
                    </asp:RoleGroup>
                    <asp:RoleGroup Roles="publisher">
                        <ContentTemplate>
                            <ul>
                                <li>Make article request.</li>
                                <li>Publish reviewed article.</li>
                            </ul>
                        </ContentTemplate>
                    </asp:RoleGroup>
                </RoleGroups>
            </asp:LoginView>
        </form>
    </body>
</html>

備註

屬性 RoleGroups 包含與網站上各種角色相關聯的內容範本。 屬性中的 RoleGroups 集合會依來源中定義範本的順序進行搜尋。 第一個相符的角色群組範本會顯示給使用者。 如果使用者是多個角色的成員,則會使用符合任何使用者角色的第一個角色群組範本。 如果多個範本與單一角色相關聯,則只會使用第一個定義的範本。

如果登入的使用者不屬於角色群組集合中包含的任何角色,網站會顯示 屬性中指定的 LoggedInTemplate 內容範本。 匿名使用者永遠不會顯示集合中包含的 RoleGroups 任何範本。

您必須設定角色管理,才能使用 RoleGroups 屬性,根據使用者在網站上的角色來定義範本。 如需詳細資訊,請參閱 瞭解角色管理

這個屬性無法由佈景主題或樣式表主題設定。 如需詳細資訊,請參閱 ThemeableAttributeASP.NET 主題和麵板

適用於

另請參閱