Roles.DeleteCookie Method
.NET Framework 2.0
Deletes the cookie where role names are cached.
Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)
Roles Members
System.Web.Security Namespace
Assembly: System.Web (in system.web.dll)
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.
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 (Visual Studio). |
<%@ 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>
Reference
Roles ClassRoles Members
System.Web.Security Namespace
Other Resources
Understanding Role ManagementCommunity Additions
ADD
Show:
Security Note: