WebSecurity.Login Method
Logs the user in.
Namespace: WebMatrix.WebData
Assembly: WebMatrix.WebData (in WebMatrix.WebData.dll)
Syntax
'Declaration
Public Shared Function Login ( _
userName As String, _
password As String, _
persistCookie As Boolean _
) As Boolean
'Usage
Dim userName As String
Dim password As String
Dim persistCookie As Boolean
Dim returnValue As Boolean
returnValue = WebSecurity.Login(userName, _
password, persistCookie)
public static bool Login(
string userName,
string password,
bool persistCookie
)
public:
static bool Login(
String^ userName,
String^ password,
bool persistCookie
)
static member Login :
userName:string *
password:string *
persistCookie:bool -> bool
public static function Login(
userName : String,
password : String,
persistCookie : boolean
) : boolean
Parameters
- userName
Type: System.String
The user name.
- password
Type: System.String
The password.
- persistCookie
Type: System.Boolean
(Optional) true to specify that the authentication token in the cookie should be persisted beyond the current session; otherwise false. The default is false.
Return Value
Type: System.Boolean
true if the user was logged in; otherwise, false.
Exceptions
Exception | Condition |
---|---|
InvalidOperationException | The SimpleMembershipProvider.Initialize(String, NameValueCollection) method was not called. -or- The InitializeDatabaseConnection() method was not called. -or- The SimpleMembershipProvider membership provider is not registered in the configuration of your site. For more information, contact your site's system administrator. |
Remarks
When a user is logged in, ASP.NET sets an authentication token in a cookie that lets ASP.NET know on subsequent requests that the user has been logged in. If persistCookie is false, the token is valid only until the user closes the browser.