FormsAuthenticationTicket.Expiration Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan tanggal dan waktu lokal di mana tiket autentikasi formulir kedaluwarsa.
public:
property DateTime Expiration { DateTime get(); };
public DateTime Expiration { get; }
member this.Expiration : DateTime
Public ReadOnly Property Expiration As DateTime
Nilai Properti
di DateTime mana tiket autentikasi formulir kedaluwarsa.
Contoh
Contoh kode berikut menampilkan nilai FormsAuthenticationTicket properti untuk pengguna yang masuk saat ini.
Catatan
Jika tidak ada pengguna yang masuk, Identity properti akan menjadi null
dan Anda akan menerima pengecualian pengkompilasi saat mencoba mentransmisikan Identity properti sebagai FormsIdentity objek.
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(Object Src, EventArgs e)
{
Welcome.InnerHtml = "Hello, " +
Server.HtmlEncode(User.Identity.Name);
FormsIdentity id = (FormsIdentity)User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
cookiePath.Text = ticket.CookiePath;
expireDate.Text = ticket.Expiration.ToString();
expired.Text = ticket.Expired.ToString();
isPersistent.Text = ticket.IsPersistent.ToString();
issueDate.Text = ticket.IssueDate.ToString();
name.Text = ticket.Name;
userData.Text = ticket.UserData;
version.Text = ticket.Version.ToString();
}
private void Signout_Click(Object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Write("Logged out - cookie deleted.");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Forms Authentication</title>
</head>
<body>
<h3>Forms Authentication Example</h3>
<span id="Welcome" runat="server"> </span>
<form id="form1" runat="server">
<input type="submit" value="Signout" runat="server" onserverclick="Signout_Click" />
<h3>Forms Authentication Ticket Properties</h3>
<table>
<tbody>
<tr>
<td>
CookiePath:
</td>
<td><asp:Label id="cookiePath" runat="server" />
</td>
</tr>
<tr>
<td>
Expiration:
</td>
<td><asp:Label id="expireDate" runat="server" />
</td>
</tr>
<tr>
<td>
Expired:
</td>
<td><asp:Label id="expired" runat="server" />
</td>
</tr>
<tr>
<td>
IsPersistent:
</td>
<td><asp:Label id="isPersistent" runat="server" />
</td>
</tr>
<tr>
<td>
IssueDate:
</td>
<td><asp:Label id="issueDate" runat="server" />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td><asp:Label id="name" runat="server" />
</td>
</tr>
<tr>
<td>
UserData:
</td>
<td><asp:Label id="userData" runat="server" />
</td>
</tr>
<tr>
<td>
Version:
</td>
<td><asp:Label id="version" runat="server" />
</td>
</tr>
</tbody>
</table>
<p>
</p>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Welcome.InnerHtml = "Hello, " + _
Server.HtmlEncode(User.Identity.Name)
Dim id As FormsIdentity = CType(User.Identity, FormsIdentity)
Dim ticket As FormsAuthenticationTicket = id.Ticket
cookiePath.Text = ticket.CookiePath
expireDate.Text = ticket.Expiration.ToString()
expired.Text = ticket.Expired.ToString()
isPersistent.Text = ticket.IsPersistent.ToString()
issueDate.Text = ticket.IssueDate.ToString()
name.Text = ticket.Name
userData.Text = ticket.UserData
version.Text = ticket.Version.ToString()
End Sub
Sub Signout_Click(sender As Object, e As EventArgs)
FormsAuthentication.SignOut()
Response.Write("Logged out - cookie deleted.")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Forms Authentication</title>
</head>
<body>
<h3>Forms Authentication Example</h3>
<span id="Welcome" runat="server"> </span>
<form id="form1" runat="server">
<input type="submit" value="Signout" runat="server" onserverclick="Signout_Click" />
<h3>Forms Authentication Ticket Properties</h3>
<table>
<tbody>
<tr>
<td>
CookiePath:
</td>
<td><asp:Label id="cookiePath" runat="server" />
</td>
</tr>
<tr>
<td>
Expiration:
</td>
<td><asp:Label id="expireDate" runat="server" />
</td>
</tr>
<tr>
<td>
Expired:
</td>
<td><asp:Label id="expired" runat="server" />
</td>
</tr>
<tr>
<td>
IsPersistent:
</td>
<td><asp:Label id="isPersistent" runat="server" />
</td>
</tr>
<tr>
<td>
IssueDate:
</td>
<td><asp:Label id="issueDate" runat="server" />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td><asp:Label id="name" runat="server" />
</td>
</tr>
<tr>
<td>
UserData:
</td>
<td><asp:Label id="userData" runat="server" />
</td>
</tr>
<tr>
<td>
Version:
</td>
<td><asp:Label id="version" runat="server" />
</td>
</tr>
</tbody>
</table>
<p>
</p>
</form>
</body>
</html>
Keterangan
FormsAuthenticationTicket Jika dibuat menggunakan FormsAuthenticationTicket(String, Boolean, Int32) konstruktor yang tidak menyediakan parameter untuk tanggal dan waktu kedaluwarsa, Expiration properti mengembalikan nilai berdasarkan tanggal dan waktu lokal saat ini ditambah nilai timeout
parameter yang diberikan ke konstruktor.
FormsAuthenticationTicket Jika dibuat menggunakan konstruktor yang mengambil expiration
parameter, Expiration properti mengembalikan nilai yang disediakan ke expiration
parameter .