WebSecurity - Logout()
WebSecurity object
define
Logout() The method logs out the current user.
C# and VB syntax
Logout()
Example
Example C#
// Log out
WebSecurity.Logout();
// Redirect back to the home page
Response.Redirect("~/");
Example VB
' Log out
WebSecurity.Logout()
' Redirect back to the home page
Response.Redirect("~/")
Parameters
none.
Return Value
none.
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)
Notes
When a user is logged in, ASP.NET sets an authentication token in the cookie so ASP.NET knows about subsequent requests from the logged-in user.
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