Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

WebSecurity Login Method

WebSecurity - Login()


WebSecurity Object WebSecurity object


define

Login() The method logs in the specified user using a username and password.


C# and VB syntax

WebSecurity.Login(

userName, password, persistCookie

)


Example

Example C#

if (WebSecurity.Login(username,password))

{

Welcome

}

else

{

Incorrect username or password.

}

Example VB

if WebSecurity.Login(username,password)

Welcome

else

Incorrect username or password

end if


Parameters

Parameters Type Description
userName String Username
password String The user's password
persistCookie String true Specifies whether the authentication token in the cookie should persist after the current session ends; otherwise false. The default is false.

Return Value

Type Description
Boolean Returns if the user is logged in true; otherwise, returns false。

Notes

When a user is logged in, ASP.NET sets an authentication token in the cookie so ASP.NET knows about subsequent requests from the logged-in user. If persistCookie is false, the token is valid only until the user closes the browser.


Errors and exceptions

In the following cases, any access to the WebSecurity object will throw an InvalidOperationException:


Technical data

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

WebSecurity Object WebSecurity object