Roles.DeleteCookie Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Elimina la cookie donde se almacenan en caché los nombres de rol.
public:
static void DeleteCookie();
public static void DeleteCookie();
static member DeleteCookie : unit -> unit
Public Shared Sub DeleteCookie ()
Excepciones
La administración de roles no está habilitada.
Ejemplos
En el ejemplo de código siguiente se llama al DeleteCookie método para borrar los nombres de rol almacenados en caché cuando un usuario inicia sesión. Para obtener un ejemplo de un archivo de Web.config que habilita la administración de roles, vea Roles.
Importante
Este ejemplo contiene un cuadro de texto que acepta la entrada del usuario, que es una amenaza de seguridad potencial. De forma predeterminada, ASP.NET páginas web validan que la entrada del usuario no incluye elementos HTML ni de script. Para obtener más información, consulte Información general sobre vulnerabilidades de seguridad de script.
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void Login_OnClick(object sender, EventArgs args)
{
if (Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text))
{
Roles.DeleteCookie();
FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckbox.Checked);
}
else
Msg.Text = "User authentication failed. Please check your username and password and try again.";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Login</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Login</h3>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
Username: <asp:Textbox id="UsernameTextbox" runat="server" /><br />
Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><br />
<asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" />
<asp:CheckBox id="NotPublicCheckbox" runat="server" /> Check here if this is <span style="text-decoration:underline">not</span> a public computer
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Sub Login_OnClick(sender As Object, args As EventArgs)
If Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text) Then
Roles.DeleteCookie()
FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text, NotPublicCheckbox.Checked)
Else
Msg.Text = "User authentication failed. Please check your username and password and try again."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Login</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Login</h3>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
Username: <asp:Textbox id="UsernameTextbox" runat="server" /><br />
Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><br />
<asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" />
<asp:CheckBox id="NotPublicCheckbox" runat="server" /> Check here if this is <span style="text-decoration:underline">not</span> a public computer
</form>
</body>
</html>
Comentarios
El DeleteCookie método borra el contenido de la cookie que se usa para almacenar en caché los nombres de roles. Para obtener más información sobre el almacenamiento en caché de nombres de roles, consulte CacheRolesInCookie.