AuthenticatingEventArgs.UserName Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the authentication name for the user.

Namespace:   System.Web.ApplicationServices
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public string UserName { get; }

Property Value

Type: System.String

The user name to validate.

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

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("@contoso.com") >= 0)
    {
        e.Authenticated = Membership.Providers["ContosoSqlProvider"].ValidateUser(e.UserName, e.Password);
    }
    else if (e.UserName.IndexOf("@fabrikam.com") >= 0)
    {
        e.Authenticated = Membership.Providers["FabrikamSqlProvider"].ValidateUser(e.UserName, e.Password);
    }
    else
    {
        e.Authenticated = Membership.Provider.ValidateUser(e.UserName, e.Password);
    }
    e.AuthenticationIsComplete = true;
}

.NET Framework
Available since 3.5
Return to top
Show: