Latest web development tutorials

WebSecurity Login Method

WebSecurity objects WebSecurity objects

definition

Login () method using a user name and password specified by the user.


C # and VB syntax

WebSecurity.Login( userName, password, persistCookie )


Examples

Examples of C #

if (WebSecurity.Login(username,password))
{
<p>Welcome</p>
}
else
{
<p>Incorrect username or password.</p>
}

Examples VB

if WebSecurity.Login(username,password)
<p>Welcome</p>
else
<p>Incorrect username or password</p>
end if


parameter

参数 类型 描述
userName String 用户名
password String 用户密码
persistCookie String true 规定 cookie 中的身份验证令牌应该在当前会话结束后继续保留,否则为 false 。默认是 false。


return value

类型 描述
Boolean 如果用户已登录,则返回 true ,否则返回 false


Remark

When the user has logged in, set up a ASP.NET authentication token in a cookie, so that ASP.NET knows subsequent requests the user has logged on. If persistCookie is false, then the token only until the user closes the browser is valid.


Errors and exceptions

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

  • InitializeDatabaseConnection () method has not been called
  • SimpleMembership not initialized (or disabled in the site configuration)

Technical data

名称
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity objects WebSecurity objects