You can use the LoginView control to display different controls for anonymous and logged-in users by using templates <AnonymousTemplate> and <LoggedInTemplate> which implement this functionality. You can find more information from the article How to use ASP.NET membership LoginView control.

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition

The control supports one additional template that enables you to create different views based on the roles to which a user belongs. For this purpose you should:

1. Add a RoleGroups template with <asp:RoleGroup> controls.

2. Within every <asp:RoleGroup> control, you specify a comma-separated list of roles in the Roles attribute for which its <ContentTemplate> will be displayed.


The next example shows this approach:


<asp:LoginView ID=”LoginViewCtrl” runat=”server”>


<h2>You are anonymous</h2>



<h2>You are logged in</h2>

Submit your comment: <asp:TextBox runat=”server” ID=”CommentText” />

<br />

<asp:Button runat=”server” ID=”SubmitCommentAction” Text=”Submit” />



<asp:RoleGroup Roles=”Admin”>


<h2>Only Admins will see this</h2>



<asp:RoleGroup Roles=”Supervisor“>


<h2>This is for Supervisors!</h2>



<asp:RoleGroup Roles=”Tester, Designer”>


<h2>This is for web designers and testers</h2>