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
Place a LoginView control on your page.
In the control, create a LoggedInTemplate, and in the template, create content that should be visible only to authenticated users.
In the control, create a AnonymousTemplate, and in the template, create the content that should be visible to users who have not logged in.
Example
<asp:LoginView ID="LoginView1" Runat="server">
<LoggedInTemplate>
<asp:LoginName ID="LoginName1" Runat="server"
FormatString ="Welcome, {0}" />
<br />
<asp:HyperLink ID="HyperLink1" Runat="server"
NavigateUrl="~/MemberPages/ChangePassword.aspx">
Change Password
</asp:HyperLink>
</LoggedInTemplate>
<AnonymousTemplate>
<asp:Login id="Login1" runat="server"
CreateUserText="Create a new user..."
CreateUserUrl="~/Register.aspx"
PasswordRecoveryUrl="~/Recovery.aspx"
UserNameLabelText="E-mail address:" />
</AnonymousTemplate>
</asp:LoginView>
The code example shows a declarative syntax for a LoginView control with both a logged-in and anonymous template.
See Also
Reference
ASP.NET Login Controls Overview