Skip to content

Instantly share code, notes, and snippets.

@dsolovay
Created November 13, 2020 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsolovay/4ac71aec4126ec8f490270b1d596758d to your computer and use it in GitHub Desktop.
Save dsolovay/4ac71aec4126ec8f490270b1d596758d to your computer and use it in GitHub Desktop.
Get xConnect Contact ID (for use in Experience Profile, etc.)
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Session Info</title>
</head>
<body>
<h1>Session Info</h1>
<form id="form1" runat="server">
<div>
<p>Analytics Cookie Value</p>
<%= Sitecore.Analytics.Tracker.Current.Contact.ContactId %>
<p>Main Contact ID</p>
<% using (var client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient()) { %>
<%
var reference = new Sitecore.XConnect.IdentifiedContactReference("xDB.Tracker", Sitecore.Analytics.Tracker.Current.Contact.ContactId.ToString("N"));
var contact = client.GetAsync<Sitecore.XConnect.Contact>(reference, new Sitecore.XConnect.ContactExecutionOptions(new
Sitecore.XConnect.ContactExpandOptions() { }), System.Threading.CancellationToken.None).Result;%>
<% Response.Write("contact.Id);%>
<% } %>
</div>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment