Latest web development tutorials

WebSecurity IsAuthenticated property

WebSecurity objects WebSecurity objects

definition

IsAuthenticated attribute is a Boolean value that indicates whether the current user has been authenticated (logged in).

If the current user has been authenticated, the attribute value is a Boolean value true, otherwise it is false.


C # and VB syntax

WebSecurity.IsAuthenticated


Examples

Examples of C #

if (!WebSecurity.IsAuthenticated)
{
Response.Redirect("~/Account/Login");
}

Examples VB

if !WebSecurity.IsAuthenticated then
Response.Redirect("~/Account/Login")
end if


Remark

IsAuthenticated property is read-only. It can not change the code.


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