How to use LoggedInTemplate and AnonymousTemplate in LoginView

LoggedInTemplate and AnonymousTemplate in LoginView Control
LoginView is an 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 are displayed for the logged in users only. we can also create template for the members of particular logged in role groups.

the following example code demonstrate us how can we create different templates for authenticated users and anonymous users in an application.

in this bellow 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 dolphin. and when anonymous users visit the page they can only see a smaller image version of dolphin.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">


<html xmlns="">
<head id="Head1" runat="server">
    <title>LoginView control example: using LoggedInTemplate and AnonymousTemplate</title>
    <form id="form1" runat="server">
        <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">
                <h2>Only LoggedIn user can see Big image</h2>
                <asp:Image ID="Image1" runat="server" ImageUrl="~/images/Dolphin.jpg" Width="486" Height="354" />
                <h2>Small image for Anonymous user.</h2>
                <asp:Image ID="Image1" runat="server" ImageUrl="~/images/Dolphin.jpg" Width="162" Height="118" />

Related examples