Sintaxis declarativa del control de servidor Web LoginView
Actualización: noviembre 2007
Utiliza plantillas para mostrar contenido variante a un usuario dado, basado en el estado de autenticación y la suscripción a funciones del usuario.
<asp:LoginView
EnableTheming="True|False"
EnableViewState="True|False"
ID="string"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
OnViewChanged="ViewChanged event handler"
OnViewChanging="ViewChanging event handler"
runat="server"
SkinID="string"
Visible="True|False"
>
<AnonymousTemplate>
<!-- child controls -->
</AnonymousTemplate>
<LoggedInTemplate>
<!-- child controls -->
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup
Roles="string"
>
<ContentTemplate>
<!-- child controls -->
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
Comentarios
El control LoginView presenta diferentes plantillas de contenido de sitio Web (o vistas) para distintos usuarios basándose en si el usuario se ha autenticado y, en tal caso, a qué funciones del sitio Web pertenece.
Para obtener más información sobre el uso del control LoginView y otros controles de inicio de sesión, vea Información general sobre controles de inicio de sesión de ASP.NET.
Ejemplo
En el ejemplo de código siguiente se muestra cómo establecer las plantillas para cada uno de los tres tipos de plantillas que admite el control LoginView.
<%@ 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>
<%@ Page Language="C#" %>
<!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>