Export (0) Print
Expand All

LoginView Class

Note: This class is new in the .NET Framework version 2.0.

Displays the appropriate content template for a given user, based on the user's authentication status and role membership.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

'Declaration
<BindableAttribute(False)> _
<ThemeableAttribute(True)> _
Public Class LoginView
	Inherits Control
	Implements INamingContainer
'Usage
Dim instance As LoginView

/** @attribute BindableAttribute(false) */ 
/** @attribute ThemeableAttribute(true) */ 
public class LoginView extends Control implements INamingContainer
BindableAttribute(false) 
ThemeableAttribute(true) 
public class LoginView extends Control implements INamingContainer

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.

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>
    <BODY>
        <FORM 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>

System.Object
   System.Web.UI.Control
    System.Web.UI.WebControls.LoginView

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft