Share via


ServiceCredentials.WindowsAuthentication 屬性

定義

取得此服務的目前 Windows 驗證設定。

public:
 property System::ServiceModel::Security::WindowsServiceCredential ^ WindowsAuthentication { System::ServiceModel::Security::WindowsServiceCredential ^ get(); };
public System.ServiceModel.Security.WindowsServiceCredential WindowsAuthentication { get; }
member this.WindowsAuthentication : System.ServiceModel.Security.WindowsServiceCredential
Public ReadOnly Property WindowsAuthentication As WindowsServiceCredential

屬性值

WindowsServiceCredential

WindowsServiceCredential 執行個體。

範例

下列程式碼會示範如何使用這個屬性取得服務使用之認證的執行個體。

// Create a service host.
Uri httpUri = new Uri("http://localhost/Calculator");
ServiceHost sh = new ServiceHost(typeof(Calculator), httpUri);

// Create a binding that uses a WindowsServiceCredential.
WSHttpBinding b = new WSHttpBinding(SecurityMode.Message);
b.Security.Message.ClientCredentialType = MessageCredentialType.Windows;

// Add an endpoint.
sh.AddServiceEndpoint(typeof(ICalculator), b, "WindowsCalculator");

// Get a reference to the WindowsServiceCredential object.
WindowsServiceCredential winCredential =
    sh.Credentials.WindowsAuthentication;
// Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}",
    winCredential.IncludeWindowsGroups);
Console.WriteLine("UserNamePasswordValidationMode: {0}",
    winCredential.AllowAnonymousLogons);

Console.ReadLine();
' Create a service host.
Dim httpUri As New Uri("http://localhost/Calculator")
Dim sh As New ServiceHost(GetType(Calculator), httpUri)

' Create a binding that uses a WindowsServiceCredential.
Dim b As New WSHttpBinding(SecurityMode.Message)
b.Security.Message.ClientCredentialType = MessageCredentialType.Windows

' Add an endpoint.
sh.AddServiceEndpoint(GetType(ICalculator), b, "WindowsCalculator")

' Get a reference to the WindowsServiceCredential object.
Dim winCredential As WindowsServiceCredential = sh.Credentials.WindowsAuthentication
' Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}", winCredential.IncludeWindowsGroups)
Console.WriteLine("UserNamePasswordValidationMode: {0}", winCredential.AllowAnonymousLogons)

Console.ReadLine()

備註

使用此類別並藉由設定 AllowAnonymousLogons 屬性,指定是否允許匿名 Windows 使用者存取。 同時,使用此類別並藉由設定 AuthorizationContext 屬性,指定是否要將使用者所屬的群組資訊包含在 IncludeWindowsGroups 中。

適用於