WebSecurity Properties - IsAuthenticated
WebSecurity Object
Definition
IsAuthenticatedThe property is a Boolean value that indicates whether the current user has been authenticated (logged in).
If the current user is authenticated, the property value is a Boolean valuetrue, otherwise it isfalse。
C# and VB Syntax
WebSecurity.IsAuthenticated
Example
Example C#
if (!WebSecurity.IsAuthenticated)
{
Response.Redirect("~/Account/Login");
}
{
Response.Redirect("~/Account/Login");
}
Example VB
if !WebSecurity.IsAuthenticated then
Response.Redirect("~/Account/Login")
end if
Response.Redirect("~/Account/Login")
end if
Remarks
IsAuthenticatedThe property is read-only. It cannot be changed through code.
Errors and Exceptions
In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:
- InitializeDatabaseConnection()method has not been called
- SimpleMembershipnot initialized (or disabled in website configuration)
Technical Data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity Object Other Extensions