WebSecurity.Login Method
Logs the user in.
Assembly: WebMatrix.WebData (in WebMatrix.WebData.dll)
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.
| 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. |
The following example shows how to use the Login(String, String, Boolean) method to log in a user.
// Attempt to login the user. if (WebSecurity.Login(username, password)) { // Greet the user. <p>Welcome @username.</p> <p>Click <a href="MemberContent.cshtml">here</a> to continue.</p> } else { // Login failed. <p>Incorrect username or password.</p> }