LoggedInTemplate and AnonymousTemplate in LoginView Control
LoginView is an asp.net web server control. LoginView control displays
the appropriate content template for a given user, based on the user
authentication status and role membership.
The LoginView control includes two templated views that are displayed to the user. Those are AnonymousTemplate and LoggedInTemplate. AnonymousTemplate is displayed to the users who are not logged in. Anonymous users are those who are not logged in. LoggedInTemplete is displayed for logged-in users only. We can also create templates for the members of particular logged-in role groups.
The following asp.net example code demonstrates to us how can we create different templates for authenticated users and anonymous users in an asp.net application.
In the below example code, we created two templates view for authenticated users and anonymous users. When authenticated users visit the specified page, they can see a big image of a dolphin. And when anonymous users visit the page they can only see a smaller image version of the dolphin.
The LoginView control includes two templated views that are displayed to the user. Those are AnonymousTemplate and LoggedInTemplate. AnonymousTemplate is displayed to the users who are not logged in. Anonymous users are those who are not logged in. LoggedInTemplete is displayed for logged-in users only. We can also create templates for the members of particular logged-in role groups.
The following asp.net example code demonstrates to us how can we create different templates for authenticated users and anonymous users in an asp.net application.
In the below example code, we created two templates view for authenticated users and anonymous users. When authenticated users visit the specified page, they can see a big image of a dolphin. And when anonymous users visit the page they can only see a smaller image version of the dolphin.
Default.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>LoginView control example: using LoggedInTemplate and AnonymousTemplate</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>LoginView Example</h1>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<br /><br />
<asp:LoginName ID="LoginName2" runat="server" FormatString="Hi {0}!" Font-Size="XX-Large" ForeColor="DeepPink" />
<br />
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<h2>Only LoggedIn user can see Big image</h2>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/Dolphin.jpg" Width="486" Height="354" />
</LoggedInTemplate>
<AnonymousTemplate>
<h2>Small image for Anonymous user.</h2>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/Dolphin.jpg" Width="162" Height="118" />
</AnonymousTemplate>
</asp:LoginView>
</div>
</form>
</body>
</html>