Share via


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 Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。 詳細については、「スクリプトによる攻略の概要」を参照してください。

<%@ 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 、ロール名のキャッシュに使用される Cookie の内容をクリアします。 ロール名のキャッシュの詳細については、「」を参照してください CacheRolesInCookie

適用対象

こちらもご覧ください