Edytuj

Udostępnij za pośrednictwem


UserNamePasswordServiceCredential.CacheLogonTokens Property

Definition

Gets or sets a value that indicates whether logon tokens are cached.

public:
 property bool CacheLogonTokens { bool get(); void set(bool value); };
public bool CacheLogonTokens { get; set; }
member this.CacheLogonTokens : bool with get, set
Public Property CacheLogonTokens As Boolean

Property Value

true if logon tokens are cached; otherwise, false. The default is false.

Examples

The following example gets the value of this property.

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

// Create a binding that uses a username/password credential.
WSHttpBinding b = new WSHttpBinding(SecurityMode.Message);
b.Security.Message.ClientCredentialType = MessageCredentialType.UserName;

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

// Get a reference to the UserNamePasswordServiceCredential object.
UserNamePasswordServiceCredential unpCredential =
    sh.Credentials.UserNameAuthentication;
// Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}",
    unpCredential.IncludeWindowsGroups);
Console.WriteLine("UserNamePasswordValidationMode: {0}",
    unpCredential.UserNamePasswordValidationMode);
Console.WriteLine("CachedLogonTokenLifetime.Minutes: {0}",
    unpCredential.CachedLogonTokenLifetime.Minutes );
Console.WriteLine("CacheLogonTokens: {0}",
    unpCredential.CacheLogonTokens );
Console.WriteLine("MaxCachedLogonTokens: {0}",
    unpCredential.MaxCachedLogonTokens );

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 username/password credential.
Dim b As New WSHttpBinding(SecurityMode.Message)
b.Security.Message.ClientCredentialType = MessageCredentialType.UserName

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

' Get a reference to the UserNamePasswordServiceCredential object.
Dim unpCredential As UserNamePasswordServiceCredential = sh.Credentials.UserNameAuthentication
' Print out values.
Console.WriteLine("IncludeWindowsGroup: {0}", unpCredential.IncludeWindowsGroups)
Console.WriteLine("UserNamePasswordValidationMode: {0}", unpCredential.UserNamePasswordValidationMode)
Console.WriteLine("CachedLogonTokenLifetime.Minutes: {0}", unpCredential.CachedLogonTokenLifetime.Minutes)
Console.WriteLine("CacheLogonTokens: {0}", unpCredential.CacheLogonTokens)
Console.WriteLine("MaxCachedLogonTokens: {0}", unpCredential.MaxCachedLogonTokens)

Console.ReadLine()

Remarks

By default, WCF security asks the Windows security subsystem to create a logon token for every incoming user name/password security token if the user name is being mapped to a Windows account. This behavior can be changed by setting the UserNamePasswordValidationMode property.

For Windows mode, the service uses Win32's LogonUser function for user name/password authentication. If the CacheLogonTokens is set to true, the resulting Windows token is cached and reused for the same user name/password pair. The cache is valid for CachedLogonTokenLifetime. The maximum number of caches is limited to MaxCachedLogonTokens.

Applies to