PassportIdentity.TicketAge
PassportIdentity.TicketAge
Declares the amount of time, in seconds, that has passed since a user's Ticket was issued or refreshed. The Ticket timestamp is provided either in the Microsoft .NET Passport Ticket cookie or the query string.
Syntax
public int TicketAge [get]
Property value
An integer value which gives the time, in seconds, since a silent or manual sign-in was performed.
Example
The following C# example displays the value of the TimeSinceSignIn and the TicketAge for the authenticated user.
<%@ Page Language="C#"%> <%@ Import Namespace = "System.Web.Security" %> <HTML> <HEAD><TITLE>Mysample - Exercise - CS</TITLE></HEAD> <Script language="C#" runat="server"> string sServer; PassportIdentity oMgr; string sthisURL, sruURL; protected void Page_Load(Object src, EventArgs e) { sServer = Request.ServerVariables["SERVER_NAME"]; oMgr = (PassportIdentity)User.Identity; sthisURL = "https://" + sServer + Request.ServerVariables["SCRIPT_NAME"]; sruURL = "https://" + sServer + "/BriefCS/default.aspx"; } </Script> <% if (oMgr.IsAuthenticated) { //Set the sign-out URL - return to the default.asp sruURL = sruURL; } else { //Set the sign-in URL - stay on this page sruURL = sthisURL; } Response.Write ("<DIV STYLE = 'position:absolute; right:50px'>" + oMgr.LogoTag2(sruURL,3600,true,null,1033,false,null,-1,false) + "</DIV>"); if (oMgr.GetIsAuthenticated(3600,false,false)) { Response.Write ("<br>You are authenticated."); if (oMgr.HasTicket) { //Get and print out the TimeSinceSign property value. //Get and print out the TicketAge property value. Response.Write ("<br>You manually signed in " + oMgr.TimeSinceSignIn + " seconds ago. (TimeSinceSignIn)"); Response.Write ("<br>Your ticket was last refreshed " + oMgr.TicketAge + " seconds ago. (TicketAge)"); } } else { Response.Write ("<br>You have not been authenticated within the last hour. Please sign in or exit."); } // End If GetIsAuthenticated %> </HTML>
Output for an authenticated user will be similar to the following:
You are authenticated. You manually signed in 223 seconds ago. (TimeSinceSignIn) Your ticket was last refreshed 16 seconds ago. (TicketAge)
Remarks
A read-only property. This property checks the sign-in timestamp provided in the .NET Passport Ticket and calculates how many seconds have passed since the user's Ticket was issued or refreshed.
A Ticket contains two timestamps: the time of the last Ticket refresh (whether silent or manual), and the time of the last manual sign-in (that is, the last time the user actually typed in a password on the Login server form page). This property gives the difference between when the user's Ticket was issued or refreshed and the current time, in seconds.
The TicketAge property will be returned for any authenticated user. If you attempt to retrieve the TicketAge property of a unauthenticated user, an error is returned. In the preceding example, the TicketAge of the authenticated user is displayed along with the TimeSinceSignIn. In this example, the Ticket is silently refreshed whenever the authentication becomes stale (when the TicketAge is greater than iTimeWindow). In the results, the TimeSinceSignIn (manual sign-in) and the TicketAge (sign-in) are different values because the silent sign-in has occurred to refresh the Ticket.
You are advised to check HasTicket before calling TicketAge or TimeSinceSignIn, which would return a run-time error if no Ticket were present.
See Also
Passport PassportIdentity Object | PassportIdentity.TimeSinceSignIn | PassportIdentity.IsAuthenticated | PassportIdentity.HasTicket