System.Web.Security Namespace WindowsAuthenticationModule Class
Occurs when the application authenticates the current request.
[ VB ]
Public Event Authenticate As WindowsAuthenticationEventHandler
[ C# ]
public event WindowsAuthenticationEventHandler Authenticate;
[ C++ ]
public: __event WindowsAuthenticationEventHandler* Authenticate;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The Authenticate event is raised during the AuthenticateRequest event and is used to ensure that the User property of the current HttpContext is populated with an IPrincipal object.
You can handle the Authenticate event of the WindowsAuthenticationModule class by specifying a subroutine named WindowsAuthentication_OnAuthenticate in the Global.asax file for your ASP.NET application.
You can use the User property of the WindowsAuthenticationEventArgs object supplied to the WindowsAuthentication_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 supplied during the WindowsAuthentication_OnAuthenticate event, the Windows identity supplied by IIS is used as the identity for the current request.
If IIS uses anonymous authentication, then the Identity property is set to the identity returned by the GetAnonymous method.
The WindowsAuthentication_OnAuthenticate event is only raised when the authentication Mode is set to Windows in the authorization element of the application's configuration file and the WindowsAuthenticationModule is an active HTTP module for the application.
Information related to the Authenticate event is passed via a WindowsAuthenticationEventArgs object to the method assigned to handle the event. The following WindowsAuthenticationEventArgs properties provide information specific to this event.
Property |
Description |
Context |
Gets the HttpContext object for the current HTTP request. |
Identity |
Gets the Windows identity passed to the WindowsAuthenticationEventArgs constructor. |
User |
Gets or sets the IPrincipal object to be associated with the current request. |
The following code example uses the WindowsAuthentication_OnAuthenticate event to set the User property of the current HttpContext to a custom IPrincipal object.
public void WindowsAuthentication_OnAuthenticate ( object sender, WindowsAuthenticationEventArgs args ) {
if ( !args.Identity.IsAnonymous ) {
args.User = new Samples.AspNet.Security.MyPrincipal ( args.Identity );
}
}
Public Sub WindowsAuthentication_OnAuthenticate ( sender As Object, args As WindowsAuthenticationEventArgs )
If Not args.Identity.IsAnonymous Then
args.User = New Samples.AspNet.Security.MyPrincipal ( args.Identity )
End If
End Sub |
|
C# |
VB |
WindowsAuthenticationModule Members