AuthenticatingEventArgs.UserName Właściwość

Definicja

Pobiera nazwę uwierzytelniania użytkownika.

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

Wartość właściwości

Nazwa użytkownika do zweryfikowania.

Przykłady

Poniższy przykład przedstawia procedurę obsługi zdarzeń, która wybiera dostawcę członkostwa do użycia na podstawie wartości UserName właściwości. Procedura obsługi przekazuje UserName wartości i Password do niestandardowego dostawcy członkostwa w celu zweryfikowania poświadczeń użytkownika. Ustawia Authenticated wartość zwracaną ValidateUser metody i ustawia AuthenticationIsComplete wartość na true , aby AuthenticationService klasa nie weryfikowała poświadczeń.

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;
}
Sub AuthenticationService_Authenticating _
   (ByVal sender As Object, _
    ByVal e As System.Web.ApplicationServices.AuthenticatingEventArgs)
    
    If (e.Username.IndexOf("@contoso.com") >= 0) Then
        e.Authenticated = Membership.Providers("ContosoSqlProvider").ValidateUser(e.Username, e.Password)
    ElseIf (e.Username.IndexOf("@fabrikam.com") >= 0) Then
        e.Authenticated = Membership.Providers("FabrikamSqlProvider").ValidateUser(e.Username, e.Password)
    Else
        e.Authenticated = Membership.Provider.ValidateUser(e.Username, e.Password)
    End If
    e.AuthenticationIsComplete = True
End Sub

Uwagi

Właściwość służy do pobierania UserName nazwy uwierzytelniania podczas Authenticating zdarzenia.

Dotyczy

Zobacz też