WebSecurity - Logout()
WebSecurity Object
Definition
Logout()Logs out the current user.
C# and VB Syntax
Logout()
Examples
Example C#
// Log out
WebSecurity.Logout();
// Redirect back to homepage
Response.Redirect("~/");
WebSecurity.Logout();
// Redirect back to homepage
Response.Redirect("~/");
Example VB
' Log out
WebSecurity.Logout()
' Redirect back to homepage
Response.Redirect("~/")
WebSecurity.Logout()
' Redirect back to homepage
Response.Redirect("~/")
Parameters
None.
Return Value
None.
Errors and Exceptions
In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:
- InitializeDatabaseConnection()The method is not called
- SimpleMembershipNot initialized (or disabled in the website configuration)
Remarks
When the user is logged in, ASP.NET sets an authentication token in a cookie to let ASP.NET know on subsequent requests that the user is logged in.
Logout()The method removes the authentication token and logs out the user.
Technical Data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity Object Other Extensions