次の方法で共有


DefaultAuthenticationEventArgs コンストラクタ

DefaultAuthenticationEventArgs クラスの新しいインスタンスを初期化します。

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

構文

'宣言
Public Sub New ( _
    context As HttpContext _
)
'使用
Dim context As HttpContext

Dim instance As New DefaultAuthenticationEventArgs(context)
public DefaultAuthenticationEventArgs (
    HttpContext context
)
public:
DefaultAuthenticationEventArgs (
    HttpContext^ context
)
public DefaultAuthenticationEventArgs (
    HttpContext context
)
public function DefaultAuthenticationEventArgs (
    context : HttpContext
)
適用できません。

パラメータ

  • context
    イベントのコンテキスト。

解説

DefaultAuthenticationModule オブジェクトは、現在の HttpContext を使用して DefaultAuthenticationEventArgs オブジェクトを生成し、それを DefaultAuthentication_OnAuthenticate イベントに渡します。

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

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

使用例

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

メモメモ :

DefaultAuthentication_OnAuthenticate イベントは、AuthorizeRequest イベントの前に発生します。結果、現在の HttpContextUser プロパティにカスタム 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]);
}

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

DefaultAuthenticationEventArgs クラス
DefaultAuthenticationEventArgs メンバ
System.Web.Security 名前空間

その他の技術情報

ASP.NET の認証