This documentation is archived and is not being maintained.

FormsAuthentication.SignOut Method

Removes the authentication ticket.

[Visual Basic]
Public Shared Sub SignOut()
[C#]
public static void SignOut();
[C++]
public: static void SignOut();
[JScript]
public static function SignOut();

Remarks

This removes either durable or session cookies.

Example

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="true" %>
<script runat="server">

    Sub Page_Load(sender as Object, e as EventArgs) 
        If Request.IsAuthenticated = true Then
            Status.Text = "User " + User.Identity.Name + " is currently logged in."
        End If
    End Sub
    
    ' The LogOffBtn_Click event handler uses the SignOut method
    ' to remove the authentication ticket from the users computer.
    
    Sub LogOffBtn_Click(sender as Object, e as EventArgs)     
        FormsAuthentication.SignOut()
        Status.Text = "Not authenticated."
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <h2>Log Off Page 
        </h2>
        <hr size="1" />
        <p>
            Status: 
            <asp:Label id="Status" runat="server" ForeColor="red"></asp:Label>
        </p>
        <asp:button id="LogOffBtn" onclick="LogOffBtn_Click" runat="server" text="Log Off"></asp:button>
    </form>
</body>
</html>

[C#] 
<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">

    void Page_Load(Object sender, EventArgs e) 
    {
    
        if (Request.IsAuthenticated == true) 
        {
            Status.Text = "User " + User.Identity.Name + " is currently logged in.";
        }
    }
    
    // The LogOffBtn_Click event handler uses the SignOut method
    // to remove the authentication ticket from the users computer.
    
    void LogOffBtn_Click(Object sender, EventArgs e) 
    {
        FormsAuthentication.SignOut();
        Status.Text = "Not authenticated.";
    }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <h2>Log Off Page 
        </h2>
        <hr size="1" />
        <p>
            Status: 
            <asp:Label id="Status" runat="server" ForeColor="red"></asp:Label>
        </p>
        <asp:button id="LogOffBtn" onclick="LogOffBtn_Click" runat="server" text="Log Off"></asp:button>
    </form>
</body>
</html>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

FormsAuthentication Class | FormsAuthentication Members | System.Web.Security Namespace

Show: