This documentation is archived and is not being maintained.

AuthenticationService::Login Method

Checks user credentials and creates an authentication ticket (cookie) if the credentials are valid.

Namespace:  System.Web.ApplicationServices
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

[OperationContractAttribute]
public:
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.

Return Value

Type: System::Boolean
true if user credentials are valid; otherwise, false.

ExceptionCondition
ArgumentNullException

userName or password is nullptr.

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.

NoteNote

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.

NoteNote

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.

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: