FormsAuthentication.SignOut 方法 [C#]请参见 FormsAuthentication 类 | FormsAuthentication 成员 | System.Web.Security 命名空间 | FormsAuthentication 成员(Visual J# 语法) | C++ 托管扩展编程 要求 平台: Windows 2000, Windows XP Professional, Windows Server 2003 系列 语言 C#C++JScriptVisual Basic全部显示 移除身份验证票。[Visual Basic] Public Shared Sub SignOut()[C#] public static void SignOut();[C++] public: static void SignOut();[JScript] public static function SignOut();备注 这将移除持久性 Cookie 或会话 Cookie。示例 [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> 要求 平台: Windows 2000, Windows XP Professional, Windows Server 2003 系列
FormsAuthentication.SignOut()
Response.Redirect("login.aspx")
cookie.Expires = DateTime.Today.AddYears(-1);
FormsAuthentication 类 | FormsAuthentication 成员 | System.Web.Security 命名空间 | FormsAuthentication 成员(Visual J# 语法) | C++ 托管扩展编程
要求
平台: Windows 2000, Windows XP Professional, Windows Server 2003 系列
语言
C#C++JScriptVisual Basic全部显示
移除身份验证票。[Visual Basic]
Public Shared Sub SignOut()[C#]
public static void SignOut();[C++]
public: static void SignOut();[JScript]
public static function SignOut();备注
这将移除持久性 Cookie 或会话 Cookie。示例
[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>
要求
平台: Windows 2000, Windows XP Professional, Windows Server 2003 系列