Roles.DeleteCookie Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Apaga o cookie onde os nomes dos papéis estão guardados em cache.
public:
static void DeleteCookie();
public static void DeleteCookie();
static member DeleteCookie : unit -> unit
Public Shared Sub DeleteCookie ()
Exceções
A gestão de funções não está ativada.
Exemplos
O exemplo de código seguinte chama o DeleteCookie método para limpar quaisquer nomes de papéis em cache quando um utilizador inicia sessão. Para um exemplo de um ficheiro Web.config que permite a gestão de funções, veja Roles.
Importante
Este exemplo contém uma caixa de texto que aceita a entrada do utilizador, o que constitui uma potencial ameaça à segurança. Por defeito, as páginas Web do ASP.NET validam que a entrada do utilizador não inclui elementos de script ou HTML. Para mais informações, consulte Visão Geral dos Exploits de Scripts.
<%@ 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>
Observações
O DeleteCookie método limpa o conteúdo do cookie que é usado para armazenar em cache os nomes dos papéis. Para mais informações sobre nomes de papéis em cache, veja CacheRolesInCookie.