共用方式為


UserNamePasswordServiceCredential.CacheLogonTokens 屬性

定義

取得或設定值,這個值會指出是否要快取登入權杖。

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

屬性值

Boolean

如果要快取登入權杖,則為 true,否則為 false。 預設為 false

範例

下列範例會取得這個屬性的值。

// 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()

備註

根據預設,如果使用者名稱對應至Windows帳戶,WCF 安全性會要求Windows安全性子系統為每個傳入的使用者名稱/密碼安全性權杖建立登入權杖。 您可以設定 UserNamePasswordValidationMode 屬性來變更這種行為。

Windows 模式中,服務會使用 Win32 的 LogonUser 函式來進行使用者名稱/密碼驗證。 如果 CacheLogonTokens 設定為 true,產生的 Windows 權杖就會存放在快取中,並且重複使用於同一對使用者名稱/密碼。 快取的有效期限為 CachedLogonTokenLifetime。 快取的最大數目限定為 MaxCachedLogonTokens

適用於