System.Web.UI.WebControls.LoginView Class

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

See Also: LoginView Members

Syntax

[System.Web.UI.Themeable(true)]
[System.Web.UI.PersistChildren(false)]
[System.Web.UI.ParseChildren(true)]
[System.ComponentModel.Designer("System.Web.UI.Design.WebControls.LoginViewDesigner,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.DefaultProperty("CurrentView")]
[System.ComponentModel.DefaultEvent("ViewChanged")]
public class LoginView : System.Web.UI.Control, System.Web.UI.INamingContainer

Remarks

In this topic:

Introduction

The System.Web.UI.WebControls.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.

Note:

If you are not familiar with the set of login controls available in ASP.NET, see ASP.NET Login Controls Overview before continuing. For a list of other topics related to login controls and membership, see Managing Users By Using Membership.

The template stored in the LoginView.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 LoginView.RoleGroups property or the default template specified in the LoginView.LoggedInTemplate property.

The System.Web.UI.WebControls.LoginView control manages switching among the various templates once you assign templates to any of the three template properties of the System.Web.UI.WebControls.LoginView class:

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 System.Web.UI.WebControls.LoginView control when various combinations of templates are used.

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 LoginView.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 LoginView.LoggedInTemplate property. If the user in not logged in, displays the template specified in the LoginView.AnonymousTemplate property.

Set

Set

Set

If the user is logged in, displays the first template in the LoginView.RoleGroups collection that matches one of the user's roles. If no match is found, displays the template specified in the LoginView.LoggedInTemplate property. If the user is not logged in, displays the template specified in the LoginView.AnonymousTemplate property.

Set

Not set

Set

If the user is logged in, displays the first template in the LoginView.RoleGroups collection that matches one of the user's roles. If no match is found, displays the template specified in the LoginView.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 LoginView.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 LoginView.AnonymousTemplate property.

The LoginView.AnonymousTemplate and LoginView.LoggedInTemplate can be used with any authentication scheme that sets the System.Security.Principal.IIdentity.Name property of the System.Web.UI.Page object's System.Web.UI.Page.User property. You must configure role management to use the LoginView.RoleGroups property to define templates base on the user's role on the Web site. For more information, see Understanding ASP.NET Role Management.

The System.Web.UI.Control.Focus method does not set the initial focus of the Web page to the System.Web.UI.WebControls.LoginView control, or any of its child controls. Controls contained in the System.Web.UI.WebControls.LoginView control are created after the System.Web.UI.Control.PreRender event. To set the focus to a child control contained by the System.Web.UI.WebControls.LoginView, handle the On_PreRender and call its System.Web.UI.Control.Focus method. You can also use the LoginView.ViewChanging and LoginView.ViewChanged events to programmatically access the controls in the System.Web.UI.WebControls.LoginView control templates.

Declarative Syntax

Example

<asp:LoginView
    EnableTheming="

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0