Things inside LoggedInTemplate will be shown only if the
user is logged in where AnonymousTemplate will be visible if the user is not
logged in.
Example
<asp:LoginView ID="loginvew" runat="server">
<AnonymousTemplate>
You are not Logged in.
</AnonymousTemplate>
<LoggedInTemplate>
You are Logged in.<asp:LoginStatus ID="LoginStatus2"
runat="server" />
</LoggedInTemplate>
</asp:LoginView>
In the above example, when the user is not logged in
then it will show the text “You are not Logged in.” and when the user is logged
in it will show “You are Logged in” with a hyperlink as “Logout” to logout the
session.
Using LoginView Control with Roles
The most cool feature of this control is using it based on Roles. Suppose, if we want to display some controls based on the user
role then this control is a champion of doing it with very less effort.
Refer the below code for using it.
<asp:LoginView ID="loginvew" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="Admin">
<ContentTemplate>
<asp:Button ID="btnUpdate" runat="server"
OnClick="btnUpdate_Click" Text="Update" />
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
The above code will show the update button only if the
logged user is associated with the role “Admin”.
If we are using the LoggedInTemplate and RoleGroups
simultaneously in LoginView control then LoggedInTemplate will show the
controls/contents only if the user does not belong to any role group present in
the Rolegroups tag.
|