DirectoryEntry.Username DirectoryEntry.Username DirectoryEntry.Username DirectoryEntry.Username Property

定義

取得或設定要在驗證用戶端時使用的使用者名稱。Gets or sets the user name to use when authenticating the client.

public:
 property System::String ^ Username { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.DirectoryServices.DSDescription("DSUsername")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Username { get; set; }
member this.Username : string with get, set
Public Property Username As String

屬性值

驗證用戶端時所要使用的使用者名稱。The user name to use when authenticating the client.

範例

下列範例示範Username DirectoryEntry類別的和Password屬性。The following example demonstrates the Username and Password properties of the DirectoryEntry class. 這個範例會取得使用者指定DirectoryEntryPath和其Children所有的。This example gets the user-specified DirectoryEntry and the Path of all its Children.

Dim myADSPath As String = _  
      "LDAP://onecity/CN=Users,DC=onecity,DC=corp,DC=fabrikam,DC=com"  
  
' Create an Instance of DirectoryEntry.  
Dim myDirectoryEntry As New DirectoryEntry(myADSPath)  
myDirectoryEntry.Username = UserName  
myDirectoryEntry.Password = SecurelyStoredPassword  
  
' Get the Child ADS objects.  
Console.WriteLine("The Child ADS objects are:")  
Dim myChildDirectoryEntry As DirectoryEntry  
For Each myChildDirectoryEntry In  myDirectoryEntry.Children  
   Console.WriteLine(myChildDirectoryEntry.Path)  
Next myChildDirectoryEntry  
String myADSPath = "LDAP://onecity/CN=Users,DC=onecity,DC=corp,DC=fabrikam,DC=com";  
  
// Create an Instance of DirectoryEntry.  
DirectoryEntry myDirectoryEntry = new DirectoryEntry(myADSPath);  
myDirectoryEntry.Username = UserName;  
myDirectoryEntry.Password = SecurelyStoredPassword;  
  
// Get the Child ADS objects.  
Console.WriteLine("The Child ADS objects are:");  
foreach(DirectoryEntry myChildDirectoryEntry in myDirectoryEntry.Children)  
   Console.WriteLine(myChildDirectoryEntry.Path);  
String^ myADSPath = "LDAP://onecity/CN=Users,DC=onecity,DC=corp,DC=fabrikam,DC=com";  
  
// Create an Instance of DirectoryEntry.  
DirectoryEntry^ myDirectoryEntry = new DirectoryEntry(myADSPath);  
myDirectoryEntry->Username = UserName;  
myDirectoryEntry->Password = SecurelyStoredPassword;  
  
// Get the Child ADS objects.  
Console::WriteLine("The Child ADS objects are:");  
Collections::IEnumerator^ myEnum = myDirectoryEntry->Children->GetEnumerator();  
while (myEnum->MoveNext())   
{  
    DirectoryEntry^ myChildDirectoryEntry = safe_cast<DirectoryEntry^>(myEnum->Current);  
    Console::WriteLine(myChildDirectoryEntry->Path);  
}  

備註

您可以設定Username和, Password以指定用來存取 Active Directory Domain Services 中資訊的替代認證。You can set the Username and Password in order to specify alternate credentials with which to access the information in Active Directory Domain Services. 從這個DirectoryEntry實例取得的任何其他物件(例如,至Children)都會自動使用相同的替代認證來建立。Any other DirectoryEntry objects retrieved from this instance (for example, through Children) are automatically created with the same alternate credentials.

適用於

另請參閱