Roles.DeleteCookie Method ()


Deletes the cookie where role names are cached.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

Public Shared Sub DeleteCookie

Exception Condition

Role management is not enabled.

The DeleteCookie method clears the contents of the cookie that is used to cache role names. For more information on caching role names, see CacheRolesInCookie.

The following code example calls the DeleteCookie method to clear any cached role names when a user logs in. For an example of a Web.config file that enables role management, see Roles.

System_CAPS_security Security Note

This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

Public Sub Login_OnClick(sender As Object, args As EventArgs)
   If Membership.ValidateUser(UsernameTextbox.Text, PasswordTextbox.Text) Then
      FormsAuthentication.RedirectFromLoginPage(UsernameTextbox.Text,  NotPublicCheckbox.Checked)
     Msg.Text = "User authentication failed. Please check your username and password and try again."
   End If
End Sub


<html xmlns="" >

<form id="form1" runat="server">

  <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



.NET Framework
Available since 2.0
Return to top