Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

How to: Display Different Information to Anonymous and Logged In Users

You can display different information to anonymous and logged-in (authenticated) users by including a LoginView control on the page. The LoginView control includes two templates: one for displaying information to anonymous users, and the other for displaying information to logged-in users. (You can also include templates based on role names using the RoleGroups property.)The control automatically determines whether a user is authenticated and renders the appropriate template.

To display different information to anonymous and logged-in users

  1. In Design view on an ASP.NET page, from the Login folder in the Toolbox, drag a LoginView control onto the page.

  2. If the LoginView Tasks panel is not showing, right-click the control and click Show Smart Tag to display the LoginView Tasks panel.

    By default, the control displays the AnonymousTemplate.

  3. Add static text and controls that should be visible to users who have not logged in, such as a Login control that enables users to log in, recover a password, or create a new user ID.

  4. In the LoginView Tasks menu, select LoggedInTemplate from the list of Views.

  5. Add static text and controls that should be visible to authenticated users, such as a LoginName control with the FormatString property set to a welcome message.

<asp:LoginView ID="LoginView1" Runat="server">
   <asp:LoginName ID="LoginName1" Runat="server" 
                  FormatString ="Welcome, {0}"/>
   <br />
    <asp:HyperLink ID="HyperLink1" Runat="server" 
      Change Password
    <asp:Login id="Login1" runat="server" 
        CreateUserText="Create a new user..."
        UserNameLabelText="E-mail address:" />

The code example shows a LoginView control in Source view after you have defined an AnonymousTemplate and a LoggedInTemplate.

© 2015 Microsoft