This simple and extremely powerful control allows you to display:

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

–  a different set of controls for anonymous and authenticated users.

–  different content based on which roles the currently logged-in user is assigned to

The LoginView control is a template control with different types of templates:

–  one for anonymous users

–  one for authenticated users

–  one for supporting role-based templates


<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” />




You can handle two events, supported by the control, for initializing content controls of different templates appropriately before they are displayed:

– ViewChanging, which is raised before the control displays content defined in another template

– ViewChanged, which is raised after the control has changed the content display from one template to another