AuthenticatingEventArgs.UserName AuthenticatingEventArgs.UserName AuthenticatingEventArgs.UserName AuthenticatingEventArgs.UserName Property


Gets the authentication name for the user.

 property System::String ^ UserName { System::String ^ get(); };
public string UserName { get; }
member this.UserName : string
Public ReadOnly Property UserName As String

Property Value

The user name to validate.


The following example shows an event handler that selects a membership provider to use based on the value of the UserName property. The handler passes UserName and Password values to the custom membership provider to validate the user credentials. It sets Authenticated to the return value of the ValidateUser method and sets AuthenticationIsComplete to true so that the AuthenticationService class does not validate the credentials.

void AuthenticationService_Authenticating(object sender, System.Web.ApplicationServices.AuthenticatingEventArgs e)
    if (e.UserName.IndexOf("") >= 0)
        e.Authenticated = Membership.Providers["ContosoSqlProvider"].ValidateUser(e.UserName, e.Password);
    else if (e.UserName.IndexOf("") >= 0)
        e.Authenticated = Membership.Providers["FabrikamSqlProvider"].ValidateUser(e.UserName, e.Password);
        e.Authenticated = Membership.Provider.ValidateUser(e.UserName, e.Password);
    e.AuthenticationIsComplete = true;
Sub AuthenticationService_Authenticating _
   (ByVal sender As Object, _
    ByVal e As System.Web.ApplicationServices.AuthenticatingEventArgs)
    If (e.Username.IndexOf("") >= 0) Then
        e.Authenticated = Membership.Providers("ContosoSqlProvider").ValidateUser(e.Username, e.Password)
    ElseIf (e.Username.IndexOf("") >= 0) Then
        e.Authenticated = Membership.Providers("FabrikamSqlProvider").ValidateUser(e.Username, e.Password)
        e.Authenticated = Membership.Provider.ValidateUser(e.Username, e.Password)
    End If
    e.AuthenticationIsComplete = True
End Sub


You use the UserName property to retrieve the authentication name during the Authenticating event.

Applies to

See also