Share via


PassportIdentity.TimeSinceSignIn

PassportIdentity.TimeSinceSignIn

Declares the amount of time, in seconds, since a user's manual sign-in to the Microsoft® .NET Passport Login server.

Syntax

public int TimeSinceSignIn [get]

Property value

An integer value which gives the time, in seconds, since a user's manual sign-in to the .NET Passport Login server.

Example

The following C# example displays the value of the TimeSinceSignIn property 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;
 string sthisURL;

 protected void Page_Load(Object src, EventArgs e) {
 sServer = Request.ServerVariables["SERVER_NAME"];
 sthisURL = "https://" + sServer + Request.ServerVariables["SCRIPT_NAME"];
}
</Script>
<%
//Instantiate a PassportIdentity object.
PassportIdentity oMgr = (PassportIdentity)User.Identity;

//LogoTag2 allows the user to sign in or out.
Response.Write ("<DIV STYLE = 'position:absolute; right:50px'>" + oMgr.LogoTag2(sthisURL,3600,true,null,1033,false,null,-1,false) + "</DIV>");

if (oMgr.GetIsAuthenticated(3600,false,false)) {
 Response.Write("<br>Welcome. You are authenticated.");

 //Check that there is a Ticket.
 if (oMgr.HasTicket) {
  Response.Write ("<br>You manually signed in " + oMgr.TimeSinceSignIn + " seconds ago.");
  Response.Write ("<br>Your Ticket was last refreshed " + oMgr.TicketAge + " seconds ago.");
 }
}
else {
 //Provide a message to an unauthenticated user.
 Response.Write("<br>You are not authenticated. Please click Sign In or exit the page.");
}
%>

Output for an authenticated user will be similar to the following:

Welcome. You are authenticated.
You manually signed in 356 seconds ago.
Your Ticket was last refreshed 356 seconds ago.

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 last entered credentials manually.

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 the last manual sign-in and the current time, in seconds.

Time-zone and clock skew-issues are automatically corrected by including the current time on any request to the Login server that generated the current Ticket. A Ticket is thus zero seconds old at the moment of its arrival.

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.TicketAge | PassportIdentity.IsAuthenticated | PassportIdentity.HasTicket