DefaultAuthenticationModule.Authenticate イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DefaultAuthenticationModule.Authenticate イベントの意味・解説 

DefaultAuthenticationModule.Authenticate イベント

要求が認証された後に発生します。

名前空間: System.Web.Security
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Event Authenticate As
 DefaultAuthenticationEventHandler
Dim instance As DefaultAuthenticationModule
Dim handler As DefaultAuthenticationEventHandler

AddHandler instance.Authenticate, handler
public event DefaultAuthenticationEventHandler Authenticate
public:
event DefaultAuthenticationEventHandler^ Authenticate {
    void add (DefaultAuthenticationEventHandler^ value);
    void remove (DefaultAuthenticationEventHandler^ value);
}
/** @event */
public void add_Authenticate (DefaultAuthenticationEventHandler
 value)

/** @event */
public void remove_Authenticate (DefaultAuthenticationEventHandler
 value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

Authenticate イベントは、AuthenticateRequest イベントの後に発生し、現在の HttpContext の User プロパティに必ず IPrincipal オブジェクトが格納されるようにします。

DefaultAuthenticationModule クラスの Authenticate イベントには、ASP.NET アプリケーションの Global.asax ファイルに、DefaultAuthentication_OnAuthenticate というサブルーチンを指定することによってアクセスできます。

DefaultAuthentication_OnAuthenticate イベントに渡した DefaultAuthenticationEventArgs オブジェクトの Context プロパティを使用して、現在の HttpContext の User プロパティにカスタムの IPrincipal オブジェクトを設定できます。DefaultAuthentication_OnAuthenticate イベント中に渡される HttpContext の User プロパティに対して値を指定しない場合、DefaultAuthenticationModule は、HttpContext の User プロパティに、ユーザー情報が含まれない GenericPrincipal オブジェクトを設定します。

DefaultAuthentication_OnAuthenticate イベントは、AuthenticateRequest イベントの後と AuthorizeRequest イベントの前に発生します。authorization セクションにより、アプリケーションへのアクセスの許可または拒否をユーザー名に依存している場合、現在の HttpContext の User プロパティを変更することによりアプリケーションの動作に影響を与えることがあります。構成ファイルの authorization セクションを指定するときには、必ず、DefaultAuthentication_OnAuthenticate イベントで設定されるユーザー名を考慮するようにしてください。

使用例使用例

DefaultAuthentication_OnAuthenticate イベントを使用して、現在の HttpContext の User プロパティが null 参照 (Visual Basic では Nothing) かどうかをテストするコード例を次に示します。User プロパティが null 参照 (Visual Basic では Nothing) の場合、サンプル コードでは、現在の HttpContext の User プロパティに GenericPrincipal オブジェクトが設定され、このとき、GenericPrincipal オブジェクトの Identity は Name 値が "default" の GenericIdentity になります。

メモメモ

DefaultAuthentication_OnAuthenticate イベントは、AuthorizeRequest イベントの前に発生します。結果、現在の HttpContext の User プロパティにカスタム ID を設定すると、アプリケーションの動作に影響を与える場合があります。たとえば、FormsAuthentication クラスを使用して、認証されたユーザーしかサイトにアクセスできないように authorization 構成セクションに <deny users="?" /> と指定している場合、このサンプル コードでは、ユーザーは "default" という名前を持つため deny 要素が無視されます。この場合、<deny users="default" /> と指定すると、認証されたユーザーのみがサイトにアクセスできるようになります。

Public Sub DefaultAuthentication_OnAuthenticate(sender
 As Object, _
                                                args As DefaultAuthenticationEventArgs)
  If args.Context.User Is Nothing
 Then
    args.Context.User = _
      new System.Security.Principal.GenericPrincipal( _
        new System.Security.Principal.GenericIdentity("default"),
 _
        new String(0) {})
  End If
End Sub
public void DefaultAuthentication_OnAuthenticate(object
 sender,
                                                 DefaultAuthenticationEventArgs args)
{
  if (args.Context.User == null)
    args.Context.User = 
      new System.Security.Principal.GenericPrincipal(
        new System.Security.Principal.GenericIdentity("default")
,
        new String[0]);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DefaultAuthenticationModule クラス
DefaultAuthenticationModule メンバ
System.Web.Security 名前空間
その他の技術情報
ASP.NET の認証
Global.asax 構文



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

DefaultAuthenticationModule.Authenticate イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DefaultAuthenticationModule.Authenticate イベントのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS