共用方式為


WindowsClientCredential.AllowedImpersonationLevel 屬性

定義

取得或設定允許的模擬等級。

public:
 property System::Security::Principal::TokenImpersonationLevel AllowedImpersonationLevel { System::Security::Principal::TokenImpersonationLevel get(); void set(System::Security::Principal::TokenImpersonationLevel value); };
public System.Security.Principal.TokenImpersonationLevel AllowedImpersonationLevel { get; set; }
member this.AllowedImpersonationLevel : System.Security.Principal.TokenImpersonationLevel with get, set
Public Property AllowedImpersonationLevel As TokenImpersonationLevel

屬性值

其中一個 TokenImpersonationLevel 值。

範例

下列範例將示範如何設定這個屬性。

// Create a service host.
EndpointAddress ea = new EndpointAddress("http://localhost/Calculator");
WSHttpBinding b = new WSHttpBinding(SecurityMode.Message);
b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

// Create a client. The code is not shown here. See the WCF samples
// for an example of the CalculatorClient code.

CalculatorClient cc = new CalculatorClient(b, ea);
// Get a reference to the Windows client credential object.
WindowsClientCredential winCred= cc.ClientCredentials.Windows;
Console.WriteLine("AllowedImpersonationLevel: {0}",
    winCred.AllowedImpersonationLevel);
Console.WriteLine("AllowNtlm: {0}", winCred.AllowNtlm);
Console.WriteLine("Domain: {0}", winCred.ClientCredential.Domain);

Console.ReadLine();
// Change the AllowedImpersonationLevel.
winCred.AllowedImpersonationLevel =
    System.Security.Principal.TokenImpersonationLevel.Impersonation;

Console.WriteLine("Changed AllowedImpersonationLevel: {0}",
    winCred.AllowedImpersonationLevel);
Console.ReadLine();
// Open the calculator and use it.
//cc.Open();
//Console.WriteLine(cc.Add(11, 11));

//// Close the client.
//cc.Close();
' Create a service host.
Dim ea As New EndpointAddress("http://localhost/Calculator")
Dim b As New WSHttpBinding(SecurityMode.Message)
b.Security.Message.ClientCredentialType = _
MessageCredentialType.Windows

' Create a client. The code is not shown here. See the WCF samples
' for an example of the CalculatorClient code.
Dim cc As New CalculatorClient(b, ea)
' Get a reference to the Windows client credential object.
Dim winCred As WindowsClientCredential = cc.ClientCredentials.Windows
Console.WriteLine("AllowedImpersonationLevel: {0}", _
                 winCred.AllowedImpersonationLevel)
Console.WriteLine("AllowNtlm: {0}", winCred.AllowNtlm)
Console.WriteLine("Domain: {0}", winCred.ClientCredential.Domain)

Console.ReadLine()
' Change the AllowedImpersonationLevel.
winCred.AllowedImpersonationLevel = _
System.Security.Principal.TokenImpersonationLevel.Impersonation

Console.WriteLine("Changed AllowedImpersonationLevel: {0}", _
winCred.AllowedImpersonationLevel)
Console.ReadLine()
' Open the calculator and use it.
' cc.Open()
' Console.WriteLine(cc.Add(11, 11))
' Close the client.
' cc.Close()

備註

當使用 Windows SSPI Negotiate 驗證時,這個屬性會對伺服器指定由用戶端所授與的模擬等級。 請注意,伺服器在其模擬用戶端權杖時所取得的模擬等級不單只是這個設定的功能。 它也是用來執行服務之帳戶的相關權限和網域設定的功能。

用戶端必須使用這個屬性明確設定所允許的模擬等級。

當用戶端指定匿名模擬時,即使服務上沒有執行任何模擬,用戶端仍然永遠會以匿名模式來驗證服務。 這是因為基礎 Windows 作業系統行為所致。

如需 Windows 模擬的詳細資訊,請移至 模擬和還原。 如需使用 Windows Communication Foundation 模擬的詳細資訊,請參閱 委派和模擬

適用於