Share via


PassportIdentity.HasProfile

PassportIdentity.HasProfile

Indicates whether a user has core profile data already in a cookie.

Syntax

public bool HasProfile( string strProfile )

Parameters

  • strProfile
    A string naming the profile to check for. The only valid values for this parameter are "core" and null. Both values will cause the method to check for the presence of the core profile.

Return values

true if strProfile exists in this user's profile; otherwise, false.

Example

The following C# example uses the HasProfile method to check for a valid core profile. If a valid core profile exists, the user's country and a message are displayed.

<%@ Page Language="C#"%>
<HTML>
<HEAD><TITLE>Mysample - Exercise - CS</TITLE></HEAD>
<Script language="C#" runat="server">
 PassportIdentity oMgr;

 protected void Page_Load(Object src, EventArgs e) {
  oMgr = (PassportIdentity)User.Identity;
 }
</Script>
<%
if (oMgr.GetIsAuthenticated(3600,0,-1)) {
 //Check to ensure there is a core profile.
 //If a core profile exists, display the country.
 Response.Write ("You are authenticated");

 if (oMgr.HasProfile("core")) {
  Response.Write ("<br>Your country is: " + oMgr["country"]);
 }
 else {
  Response.Write ("<br>You have no profile");
 } // End if core


}
else {
 Response.Write ("You have not been authenticated within the last hour.");
} // End if GetIsAuthenticated
%>
</HTML>

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

You are authenticated.
  Your country is: U.S.
  

Remarks

Every Microsoft® .NET Passport user has a core profile.

After the presence of a valid profile has been affirmed, the GetProfileObject can be used to get the values contained in the profile. After the core profile has been validated, the Country profile attribute can be retrieved.

See Also

Passport PassportIdentity Object | PassportIdentity.GetProfileObject