asp.net.ph

WindowsAuthenticationModule.Authenticate Event

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.

Remarks

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.

Event Data

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.

Example

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 );
   }
}
  C# VB

See Also

WindowsAuthenticationModule Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph