X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

WebSecurity - Login()


WebSecurity Object WebSecurity Object

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)

Technical Data

Name Value
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity Object WebSecurity Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook