AuthenticationService::Login Method (String^, String^, String^, Boolean)
Checks user credentials and creates an authentication ticket (cookie) if the credentials are valid.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
public: [OperationContractAttribute] bool Login( String^ username, String^ password, String^ customCredential, bool isPersistent )
Parameters
- username
-
Type:
System::String^
The user name to be validated.
- password
-
Type:
System::String^
The password for the specified user.
- customCredential
-
Type:
System::String^
The value or values to validate in addition to userName and password, if any.
- isPersistent
-
Type:
System::Boolean
A value that indicates whether the authentication ticket remains valid across sessions.
| Exception | Condition |
|---|---|
| ArgumentNullException | userName or password is null. |
The Login method validates user credentials through a membership provider. You can use the default membership provider or specify a custom membership provider at run time. The AuthenticationService class passes userName and password to the membership provider's ValidateUser method, but does not pass customCredential. If ValidateUser returns true, AuthenticationService creates an authentication ticket as a cookie. Set the isPersistent parameter to true to create an authentication ticket that lasts beyond the current session.
Note |
|---|
Always use the authentication service together with the secure sockets layer (SSL, by using HTTPS) to protect sensitive data. |
The Login method raises the Authenticating event and the CreatingCookie event. Create an event handler for Authenticating to customize authentication, such as checking the values in customCredential or validating credentials through a non-default membership provider. The values in customCredential are not validated by the default membership provider. To customize the authentication cookie, create an event handler for CreatingCookie.
Note |
|---|
Do not call the Login method from code that is executing on the Web server. You call the Login method only as part of a WCF service. For more information, see ASP.NET Authentication. |
Available since 3.5
