DefaultAuthenticationEventHandler デリゲートとは? わかりやすく解説

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

DefaultAuthenticationEventHandler デリゲート

DefaultAuthenticationModule の DefaultAuthentication_OnAuthenticate イベントを処理するメソッドを表します。

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

Public Delegate Sub DefaultAuthenticationEventHandler
 ( _
    sender As Object, _
    e As DefaultAuthenticationEventArgs _
)
Dim instance As New DefaultAuthenticationEventHandler(AddressOf
 HandlerMethod)
public delegate void DefaultAuthenticationEventHandler
 (
    Object sender,
    DefaultAuthenticationEventArgs e
)
public delegate void DefaultAuthenticationEventHandler
 (
    Object^ sender, 
    DefaultAuthenticationEventArgs^ e
)
/** @delegate */
public delegate void DefaultAuthenticationEventHandler
 (
    Object sender, 
    DefaultAuthenticationEventArgs e
)
JScript では、デリゲートは使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントのソース。

e

イベント データを格納している DefaultAuthenticationEventArgs。

解説解説

DefaultAuthenticationEventHandler デリゲートは、DefaultAuthenticationModule クラスの Authenticate イベントに対して定義されています。DefaultAuthenticationModule クラスの Authenticate イベントには、ASP.NET アプリケーションの Global.asax ファイルに、DefaultAuthentication_OnAuthenticate というサブルーチンを指定することによってアクセスできます。Authenticate イベントは、AuthenticateRequest イベントの後に発生し、現在の HttpContext の User プロパティに必ず IPrincipal オブジェクトが格納されるようにします。

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) かどうかをテストするコード例を次に示します。このプロパティが 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]);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Web.Security 名前空間



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

DefaultAuthenticationEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



DefaultAuthenticationEventHandler デリゲートのページの著作権

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

©2026 GRAS Group, Inc.RSS