PassportIdentity.HasTicket
PassportIdentity.HasTicket
Declares whether a user has a Microsoft .NET Passport Ticket as a cookie or on the query string.
Syntax
public bool HasTicket [get]
Property value
Boolean value. true if the Ticket was provided on the incoming request query string or is present as a cookie; otherwise, false.
Example
The following C# example uses HasTicket to verify that the user has a Ticket before getting and displaying the Ticket age.
<%@ 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 to be sure there is a Ticket. if (oMgr.HasTicket) { Response.Write ("<br>Your Ticket is " + oMgr.TicketAge + " seconds old."); } } else { //Provide a message to an unauthenticated user. Response.Write("<br>You are not authenticated. Please click Sign In or exit the page."); } %>
An authenticated user will provide an output similar to the following:
Welcome. You are authenticated. Your ticket is 220 seconds old.
Remarks
A read-only property. HasTicket returns true if the user has a .NET Passport Ticket in the calling domain. HasTicket returns false if no Ticket exists in the calling domain. HasTicket checks for the presence of a .NET Passport Ticket either on the query string or in a cookie. This method determines only whether the Ticket exists, not whether it is stale or current. If a user has chosen to save his or her password and has been signed in to your site before, then the user may perpetually have a cookie that has been issued by your domain.
It is advisable 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.TimeSinceSignIn | PassportIdentity.GetIsAuthenticated