UserNamePasswordServiceCredential.UserNamePasswordValidationMode 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定驗證使用者名稱和密碼的方法。
public:
property System::ServiceModel::Security::UserNamePasswordValidationMode UserNamePasswordValidationMode { System::ServiceModel::Security::UserNamePasswordValidationMode get(); void set(System::ServiceModel::Security::UserNamePasswordValidationMode value); };
public System.ServiceModel.Security.UserNamePasswordValidationMode UserNamePasswordValidationMode { get; set; }
member this.UserNamePasswordValidationMode : System.ServiceModel.Security.UserNamePasswordValidationMode with get, set
Public Property UserNamePasswordValidationMode As UserNamePasswordValidationMode
屬性值
來自 UserNamePasswordValidationMode 中列舉的值。
範例
下列範例會取得這個屬性的值。
// 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()
備註
可能的值包括:
如果這個屬性設定為 Custom,服務就會使用 CustomUserNamePasswordValidator 傳回的物件來驗證傳入訊息中的使用者名稱和密碼。
注意
當 WCF 服務裝載于 Internet Information Services (IIS) 使用傳輸層級安全性,且 UserNamePasswordValidationMode 屬性設定 Custom 為 時,自訂驗證配置會使用Windows 驗證子集。 這是因為在此案例中,IIS 會在 WCF 叫用自訂驗證器之前執行Windows 驗證。
如果這個屬性值設定為 MembershipProvider,請設定 MembershipProvider 屬性以指定成員資格提供者,這樣一來,由 MembershipProvider 屬性所指定的成員資格提供者執行個體就會被用來驗證傳入訊息中的使用者名稱和密碼。