This documentation is archived and is not being maintained.

DefaultAuthenticationEventArgs Constructor

Initializes a new instance of the DefaultAuthenticationEventArgs class.

Namespace:  System.Web.Security
Assembly:  System.Web (in System.Web.dll)

'Declaration
Public Sub New ( _
	context As HttpContext _
)
'Usage
Dim context As HttpContext 

Dim instance As New DefaultAuthenticationEventArgs(context)

Parameters

context
Type: System.Web.HttpContext

The context for the event.

The DefaultAuthenticationModule object constructs a DefaultAuthenticationEventArgs object using the current HttpContext and passes it to the DefaultAuthentication_OnAuthenticate event.

You can use the Context property of the DefaultAuthenticationEventArgs object supplied to the DefaultAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a custom IPrincipal object. If you do not specify a value for the User property of the HttpContext referenced by the Context property, the DefaultAuthenticationModule sets the User property of the HttpContext to a GenericPrincipal object that contains no user information.

The DefaultAuthentication_OnAuthenticate event is raised after the AuthenticateRequest event and before the AuthorizeRequest event. If you have an authorization section that depends on the user name to deny or allow access to your application, modifying the User property of the current HttpContext can affect the behavior of your application. Be sure that the user name you set during the DefaultAuthentication_OnAuthenticate event is considered when you specify the authorization section in your configuration.

The following code example uses the DefaultAuthentication_OnAuthenticate event to test whether the User property of the current HttpContext is Nothing. If the property is Nothing, the example sets the User property of the current HttpContext to a GenericPrincipal object where the Identity property of the GenericPrincipal object is a GenericIdentity object with a Name property value of "default".

NoteNote:

The DefaultAuthentication_OnAuthenticate event is raised before the AuthorizeRequest event. As a result, if you set the User property of the current HttpContext to a custom identity, it can affect the behavior of your application. For example, if you are using the FormsAuthentication class and you are ensuring that only authenticated users have access to your site, by using the authorization section and specifying <deny users="?" />, you will cause the deny element in this example to be ignored, as the user will have a name, which is "default". Instead you would specify <deny users="default" /> to ensure that only authenticated users can access your site.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: