ServiceCredentials.WindowsAuthentication Property

Definition

Gets the current Windows authentication settings for this service.

C#
public System.ServiceModel.Security.WindowsServiceCredential WindowsAuthentication { get; }

Property Value

A WindowsServiceCredential instance.

Examples

The following code shows how to use this property to get the instance of the credential used by the service.

C#
// 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();

Remarks

Use this class to specify whether to allow anonymous Windows users access by setting the AllowAnonymousLogons property. Also, use this class to specify whether to include a group information to which users belong in the AuthorizationContext by setting the IncludeWindowsGroups property.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1