CreatingCookieEventArgs クラス

定義

CreatingCookie イベントのデータを提供します。

public ref class CreatingCookieEventArgs : EventArgs
public class CreatingCookieEventArgs : EventArgs
type CreatingCookieEventArgs = class
    inherit EventArgs
Public Class CreatingCookieEventArgs
Inherits EventArgs
継承
CreatingCookieEventArgs

次の例は、イベントのイベント ハンドラーを CreatingCookie 示しています。 ハンドラーは、認証 Cookie をカスタマイズするためにオブジェクトから CreatingCookieEventArgs ユーザー値を取得します。 ハンドラーは、認証チケット内のプロパティのCustomCredential値を保存し、認証 Cookie が作成されたことを示すプロパティtrueを設定CookieIsSetします。

void AuthenticationService_CreatingCookie(object sender, 
    System.Web.ApplicationServices.CreatingCookieEventArgs e)
{
    FormsAuthenticationTicket ticket = new
          FormsAuthenticationTicket
            (1,
             e.UserName,
             DateTime.Now,
             DateTime.Now.AddMinutes(30),
             e.IsPersistent,
             e.CustomCredential,
             FormsAuthentication.FormsCookiePath);

    string encryptedTicket =
         FormsAuthentication.Encrypt(ticket);

    HttpCookie cookie = new HttpCookie
         (FormsAuthentication.FormsCookieName,
          encryptedTicket);
    cookie.Expires = DateTime.Now.AddMinutes(30);

    HttpContext.Current.Response.Cookies.Add(cookie);
    e.CookieIsSet = true;
}
Sub AuthenticationService_CreatingCookie(ByVal sender As Object, _
                 ByVal e As System.Web.ApplicationServices.CreatingCookieEventArgs)
    Dim ticket As FormsAuthenticationTicket = New _
       FormsAuthenticationTicket _
        (1, _
         e.Username, _
         DateTime.Now, _
         DateTime.Now.AddMinutes(30), _
         e.IsPersistent, _
         e.CustomCredential, _
         FormsAuthentication.FormsCookiePath)
        
    Dim encryptedTicket As String = FormsAuthentication.Encrypt(ticket)
    
    Dim cookie As HttpCookie = New _
        HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
    cookie.Expires = DateTime.Now.AddMinutes(30)
    
    HttpContext.Current.Response.Cookies.Add(cookie)
    e.CookieIsSet = True
End Sub

注釈

クラスは CreatingCookieEventArgs 、任意 CreatingCookie のイベント ハンドラーに値を提供します。 このクラスのプロパティを使用すると、カスタム認証 Cookie を作成するときにユーザー資格情報を取得できます。

このクラスは AuthenticationService 、ユーザーの資格情報が認証された後に、認証 Cookie を設定するときにイベントを発生 CreatingCookie させます。 このクラスは AuthenticationService オブジェクトを CreatingCookieEventArgs 構築し、任意 CreatingCookie のイベント ハンドラーに渡します。

ユーザー資格情報は、プロパティCustomCredentialUserNamePassword使用して取得します。 プロパティには CustomCredential 、ID 番号など、認証に必要な任意のカスタム値を含めることができます。 このプロパティは IsPersistent 、認証 Cookie を現在のセッションを超えて保持する必要があるかどうかを示します。 クラスが Cookie をCookieIsSettrue作成しないように、認証 Cookie を作成するAuthenticationService場合はプロパティを設定します。

プロパティ

CookieIsSet

認証クッキーが作成されたかどうかを示す値を取得または設定します。

CustomCredential

ユーザーが入力する追加の認証値を取得します。

IsPersistent

認証クッキーを現在のセッションの終了後も残すかどうかを示す値を取得します。

Password

ユーザーのパスワードを取得します。

UserName

ユーザーの名前を取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください