PassportIdentity.HexPUID
PassportIdentity.HexPUID
Gets the Microsoft® .NET Passport Unique ID (PUID) for the currently authenticated user, in hexadecimal form.
Syntax
public string HexPUID [get]
Property value
The PUID for the currently authenticated user, in hexadecimal form.
Example
The following C# example gets and displays the Name and HexPUID properties for the authenticated user. The two values are identical. The example gets the MemberIDHigh and MemberIDLow (through the GetProfileObject method), converts them to hexadecimal form, pads, concatenates, and finally displays the values. The concatenated value is the same as the Name and HexPUID properties.
<%@ Page Language="C#"%> <%@ Import Namespace = "System.Web.Security" %> <HTML> <HEAD><TITLE>Mysample - LoginUser - CS</TITLE></HEAD> <Script language="C#" runat="server"> PassportIdentity oMgr; string spuid; string smemberIdHigh, smemberIdLow; protected void Page_Load(Object src, EventArgs e) { oMgr = (PassportIdentity)Context.User.Identity; } </Script> <% if (oMgr.GetIsAuthenticated(3600,false,false)) { //You are authenticated, get the requested information //Note the Name, HexPUID and memberIdHigh concatenated with //memberIdLow are all the same value. Response.Write ("Your name is: " + oMgr.Name); Response.Write ("<br>Your unique identifier, your HexPUID is: " + oMgr.HexPUID); //Get memberIdHigh and memberIdLow. They are decimal values. smemberIdHigh = oMgr.GetProfileObject("memberIdHigh").ToString(); smemberIdLow = oMgr.GetProfileObject("memberIdLow").ToString(); Response.Write ("<br><br>memberIdHigh (decimal) = " + smemberIdHigh); Response.Write ("<br>memberIdLow (decimal) = " + smemberIdLow); //Get memberIdHigh and memberIdLow to hexadecimal values, pad, and concatenate them. smemberIdHigh = Convert.ToString(Convert.ToInt32(oMgr.GetProfileObject("memberIdHigh").ToString()),16); smemberIdLow = Convert.ToString(Convert.ToInt32(oMgr.GetProfileObject("memberIdLow").ToString()),16); Response.Write ("<br>memberIdHigh (hex) = " + smemberIdHigh); Response.Write ("<br>memberIdLow (hex) = " + smemberIdLow); spuid = String.Concat(smemberIdHigh.PadLeft(8,'0'),smemberIdLow); Response.Write ("<br>memberIds concatenated and padded is the same as the puid: " + spuid); } else { Response.Write ("You have not been authenticated within the last hour. Please exit."); } // End if GetIsAuthenticated %> </HTML>
Output for an authenticated user will be similar to the following:
Your name is: 00033FFF803B543F Your unique identifier, your HexPUID is: 00033FFF803B543F memberIdHigh (decimal) = 212991 memberIdLow (decimal) = -2143595457 memberIdHigh (hex) = 33fff memberIdLow (hex) = 803b543f memberIds concatenated and padded is the same as the puid: 00033fff803b543f
Remarks
A read-only property. The PUID in the .NET Passport profile can be used by sites to identify a user's record in their databases. The property returns the PUID of the currently connected user as a hexadecimal string. The PUID is a 64-bit numeric value.
The HexPUID property is identical to the approach of getting the MemberIDHigh and MemberIDLow, converting them to hexadecimal values and concatenating them together. The HexPUID property is identical to the user's Name property. Getting the HexPUID is more efficient that getting the MemberIDHigh and MemberIDLow and is the preferred method of obtaining this unique identifier.
The sign-in name is verified by the domain authority, but not distributed to participating sites. Uniqueness of sign-in name will always map one-to-one with uniqueness of the PUID. Therefore, use the PUID for all unique indexing and identification on your site. The network-side unique identifier that forms the basis of the PUID is assigned at the time of registration of a new unique sign-in name and .NET Passport. Although sign-in names may potentially be recycled or even reassigned by domain authorities, the network-side unique identifiers (and thus the resulting PUID) are never reused.
The HexPUID property will be returned for any authenticated user. If you attempt to retrieve the HexPUID property of an unauthenticated user, an error is returned.
See Also
Passport PassportIdentity Object | PassportIdentity.GetProfileObject | PassportIdentity.Name | .NET Passport Unique ID