UserNamePasswordServiceCredential.CacheLogonTokens 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否缓存登录令牌。
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
属性值
如果缓存登录令牌,则为 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。