WebSecurity - Login()
❮ WebSecurity
Definition
The Login() method logs in a specified user, using a username and a password.
C# and VB Syntax
WebSecurity.Login(userName,
password, persistCookie)
Examples
Example C#
if (WebSecurity.Login(username,password))
{
<p>Welcome</p>
}
else
{
<p>Incorrect username or password.</p>
}
Example VB
if WebSecurity.Login(username,password)
<p>Welcome</p>
else
<p>Incorrect username or password</p>
end if
Parameters
Parameter | Type | Description |
---|---|---|
userName | String | The user name |
password | String | The user password |
persistCookie | String | true to specify that the authentication token in the cookie should be persisted beyond the current session; otherwise false. Default is false. |
Return Value
Type | Description |
---|---|
Boolean | true if the user is logged in, otherwise false |
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.
Errors and Exceptions
Any access to the WebSecurity object throws an InvalidOperationException if:
- The InitializeDatabaseConnection() method has not been called
- SimpleMembership is not initialized (or disabled in the website configuration)
❮ WebSecurity