UserNamePasswordServiceCredential.UserNamePasswordValidationMode 属性

定义

获取或设置验证用户名和密码的方法。

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

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 返回的对象来验证传入消息中的用户名和密码。

备注

如果使用传输级安全在 Internet Information Services (IIS) 中承载 WCF 服务并且 UserNamePasswordValidationMode 属性设置为 Custom,则自定义身份验证方案会使用 Windows 身份验证的子集。 这是因为,在此情况下,IIS 会在 WCF 调用自定义验证器之前执行 Windows 身份验证。

此属性值设置为 MembershipProvider 时,通过设置 MembershipProvider 属性来指定成员资格提供程序,然后由 MembershipProvider 属性指定的成员资格提供程序实例将用于验证传入消息中的用户名和密码。

适用于