Roles.DeleteCookie 메서드

정의

역할 이름이 캐시된 쿠키를 삭제합니다.

public:
 static void DeleteCookie();
public static void DeleteCookie ();
static member DeleteCookie : unit -> unit
Public Shared Sub DeleteCookie ()

예외

역할 관리가 사용되지 않는 경우

예제

다음 코드 예제에서는 메서드를 DeleteCookie 호출하여 사용자가 로그인할 때 캐시된 역할 이름을 지웁니다. 역할 관리를 사용 하도록 설정 하는 Web.config 파일의 예제를 참조 하세요. Roles합니다.

중요

이 예제에서는 잠재적 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 되어 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ 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>

설명

이 메서드는 DeleteCookie 역할 이름을 캐시하는 데 사용되는 쿠키의 내용을 지웁니다. 역할 이름 캐싱에 대한 자세한 내용은 다음을 참조하세요 CacheRolesInCookie.

적용 대상

추가 정보