LoginView Class
Assembly: System.Web (in system.web.dll)
'Declaration <ThemeableAttribute(True)> _ <BindableAttribute(False)> _ Public Class LoginView Inherits Control Implements INamingContainer 'Usage Dim instance As LoginView
/** @attribute ThemeableAttribute(true) */ /** @attribute BindableAttribute(false) */ public class LoginView extends Control implements INamingContainer
ThemeableAttribute(true) BindableAttribute(false) public class LoginView extends Control implements INamingContainer
Not applicable.
The LoginView control displays different Web site content templates (or "views") for different users, based on whether the user is authenticated and, if so, which Web site roles he or she belongs to.
The template stored in the AnonymousTemplate property is displayed to any visitor to the Web site who has not logged in. Once a user is logged in, the site displays either a template associated with one of the user's roles in the RoleGroups property or the default template specified in the LoggedInTemplate property.
The LoginView control manages switching among the various templates once you assign templates to any of the three template properties of the LoginView class:
-
AnonymousTemplate Specifies the template to display to users who are not logged in to the Web site. Users who are logged in will never see this template.
-
LoggedInTemplate Specifies the default template to display to users who are logged in to the Web site but do not belong to any role groups with defined templates.
-
RoleGroups Specifies the template to display to logged-in users who are members of roles with defined role-group templates. Content templates are associated with particular sets of roles in RoleGroup instances.
Role-group templates are searched in the order they are defined in the source. The first matching role-group template is displayed to the user. If a user is a member of more than one role, the first role-group template that matches any of the user's roles is used. If more than one template is associated with a single role, only the first defined template is used.
The following table describes the behavior of the LoginView control when various combinations of templates are used.
| LoggedIn Template Property | Anonymous Template Property | RoleGroups Property | LoginView behavior |
|---|---|---|---|
| Not set | Not set | Not set | Displays no content. |
| Set | Not set | Not set | Displays content only when the user is logged in. |
| Not set | Set | Not set | Displays content only when the user is not logged in. |
| Not set | Not set | Set | Displays the first template in the RoleGroups collection that matches one of the user's roles. If no match is found, displays no content. |
| Set | Set | Not set | If the user is logged in, displays the template specified in the LoggedInTemplate property. If the user in not logged in, displays the template specified in the AnonymousTemplate property. |
| Set | Set | Set | If the user is logged in, displays the first template in the RoleGroups collection that matches one of the user's roles. If no match is found, displays the template specified in the LoggedInTemplate property. If the user is not logged in, displays the template specified in the AnonymousTemplate property. |
| Set | Not set | Set | If the user is logged in, displays the first template in the RoleGroups collection that matches one of the user's roles. If no match is found, displays the template specified in the LoggedInTemplate property. If the user is not logged in, nothing is displayed. |
| Not set | Set | Set | If the user is logged in, displays the first template in the RoleGroups collection that matches one of the user's roles. If no match is found, nothing is displayed. If the user is not logged in, displays the template specified in the AnonymousTemplate property. |
The AnonymousTemplate and LoggedInTemplate can be used with any authentication scheme that sets the Name property of the Page object's User property. You must configure role management to use the RoleGroups property to define templates base on the user's role on the Web site. For more information, see Understanding Role Management.
The Focus method does not set the initial focus of the Web page to the LoginView control, or any of its child controls. Controls contained in the LoginView control are created after the PreRender event. To set the focus to a child control contained by the LoginView, handle the On_PreRender and call its Focus method. You can also use the ViewChanging and ViewChanged events to programmatically access the controls in the LoginView control templates.
| Topic | Location |
|---|---|
| How to: Display Different Information to Anonymous and Logged-in Users | Building ASP .NET Web Applications |
| How to: Display Different Information to Anonymous and Logged-in Users | Building ASP .NET Web Applications |
| Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web Developer | Building ASP .NET Web Applications in Visual Studio |
| How to: Display Different Information to Anonymous and Logged In Users (Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
The following code example shows how to set templates for each of the three template types supported by the LoginView control.
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> <p> <asp:LoginStatus id="LoginStatus1" runat="server"></asp:LoginStatus></p> <p> <asp:LoginView id="LoginView1" runat="server"> <AnonymousTemplate> Please log in for personalized information. </AnonymousTemplate> <LoggedInTemplate> Thanks for logging in <asp:LoginName id="LoginName1" runat="Server"></asp:LoginName>. </LoggedInTemplate> <RoleGroups> <asp:RoleGroup Roles="Admin"> <ContentTemplate> <asp:LoginName id="LoginName2" runat="Server"></asp:LoginName>, you are logged in as an administrator. </ContentTemplate> </asp:RoleGroup> </RoleGroups> </asp:LoginView></p> </form> </body> </html>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
Reference
LoginView MembersSystem.Web.UI.WebControls Namespace
Roles