I have a scenario in which I want to return some facet data associated with an xDB contact via an ApiController
. However, when i try to access the Tracker.Current.Contact
property it is null.
What is the best solution to ensure access to a contact when performing ApiController calls?
Currently my code looks like this:
public class WidgetsController : ApiController {
[HttpGet]
public IEnumerable<Widget> Get()
{
if (Sitecore.Analytics.Tracker.Current != null)
{
var contact = Sitecore.Analytics.Tracker.Current.Contact;
if (contact != null)
{
return WidgetsRepository.Get(contact);
}
}
}