Share via


AuthenticationService.Login(String, String, String, Boolean) 方法

定义

检查用户凭据,如果凭据有效,则创建一个身份验证票证 (Cookie)。

public:
 bool Login(System::String ^ username, System::String ^ password, System::String ^ customCredential, bool isPersistent);
[System.ServiceModel.OperationContract]
public bool Login (string username, string password, string customCredential, bool isPersistent);
[<System.ServiceModel.OperationContract>]
member this.Login : string * string * string * bool -> bool
Public Function Login (username As String, password As String, customCredential As String, isPersistent As Boolean) As Boolean

参数

username
String

要验证的用户名。

password
String

指定的用户的密码。

customCredential
String

要验证的除 usernamepassword 之外的一个或多个值(如果有)。

isPersistent
Boolean

指示身份验证票证在各会话中是否都保持有效的一个值。

返回

如果用户凭据有效,则为 true;否则为 false

属性

例外

userNamepasswordnull

注解

方法 Login 通过成员资格提供程序验证用户凭据。 可以使用默认成员资格提供程序,或在运行时指定自定义成员资格提供程序。 类AuthenticationService将 和 password 传递给userName成员资格提供程序的 ValidateUser 方法,但不传递 customCredential。 如果 ValidateUser 返回 trueAuthenticationService 则创建一个身份验证票证作为 Cookie。 将 isPersistent 参数设置为 以 true 创建持续时间超过当前会话的身份验证票证。

注意

始终使用 HTTPS) 将身份验证服务与安全套接字层 (SSL 一起使用来保护敏感数据。

方法 Login 引发 Authenticating 事件和 CreatingCookie 事件。 为 Authenticating 创建事件处理程序以自定义身份验证,例如检查 中的 customCredential 值或通过非默认成员资格提供程序验证凭据。 中的 customCredential 值不会由默认成员资格提供程序验证。 若要自定义身份验证 Cookie,请为 CreatingCookie创建事件处理程序。

注意

不要从在 Web 服务器上执行的代码调用 Login 方法。 仅作为 WCF 服务的一部分调用 Login 方法。 有关详细信息,请参阅 ASP.NET 身份验证

适用于

另请参阅