WebSecurity Property - IsAuthenticated
WebSecurity object
define
IsAuthenticated The property is a Boolean value indicating whether the current user is authenticated (logged in).
If the current user is authenticated, the property value is a Boolean value true, otherwise it is false。
C# and VB syntax
WebSecurity.IsAuthenticated
Example
Example C#
if (!WebSecurity.IsAuthenticated)
{
Response.Redirect("~/Account/Login");
}
Example VB
if !WebSecurity.IsAuthenticated then
Response.Redirect("~/Account/Login")
end if
Notes
IsAuthenticated The property is read-only. It cannot be changed through code.
Errors and exceptions
In the following cases, any access to the WebSecurity object will throw an InvalidOperationException:
- InitializeDatabaseConnection() The method is not called
- SimpleMembership Not initialized (or disabled in the website configuration)
Technical data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity object