asp.net.ph

DefaultAuthenticationModule.Authenticate Event

System.Web.Security Namespace   DefaultAuthenticationModule Class


Occurs after the request has been authenticated.

[ VB ]
Public Event Authenticate As DefaultAuthenticationEventHandler

[ C# ]
public event DefaultAuthenticationEventHandler Authenticate;

[ C++ ]
public: __event DefaultAuthenticationEventHandler* Authenticate;

In [ JScript ], you can handle the events defined by a class, but you cannot define your own.

Remarks

The Authenticate event is raised after 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 DefaultAuthenticationModule class by specifying a subroutine named DefaultAuthentication_OnAuthenticate in the Global.asax file for your ASP.NET application.

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 supplied during the DefaultAuthentication_OnAuthenticate event, 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.

Event Data

Information related to the Authenticate event is passed via a DefaultAuthenticationEventArgs object to the method assigned to handle the event. The following DefaultAuthenticationEventArgs properties provide information specific to this event.

Property Description
Context Gets the HttpContext object for the current HTTP request.

Example

The following code example uses the DefaultAuthentication_OnAuthenticate event to test whether the User property of the current HttpContext is a null reference ( Nothing in Visual Basic ). If the User property is a null reference ( Nothing in Visual Basic ), then the sample sets the User property of the current HttpContext to a GenericPrincipal object where the Identity of the GenericPrincipal object is a GenericIdentity with a Name value of "default".

NOTE: 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 specify <deny users = "?" /> in the authorization configuration section to ensure that only authenticated users have access to your site, this sample will cause the deny element 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 void DefaultAuthentication_OnAuthenticate ( object src, DefaultAuthenticationEventArgs args ) {
   if ( args.Context.User == null ) {
      args.Context.User = new System.Security.Principal.GenericPrincipal (
         new System.Security.Principal.GenericIdentity ( "default" ), new String [ 0 ] );
   }
}
  C# VB

See Also

DefaultAuthenticationModule 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