Month: February 2013

Get users by taxonomy category

Ektron’s taxonomy feature allows you to categorise not only content but also users and user groups too. Putting a user into a category has all kinds of uses such as identifying users who have performed a certain task on your site like signing up to a feature or adding something to their profile.

There is a little bit of a grey area in terms of whether you would use a user group or custom user properties for some of the use cases. Taxonomy is always going to be the more powerful option as it provides a hierarchical structure whereas groups and properties are flat.  Taxonomies themselves can also be extended through the use of custom properties on the category.

So consider what you will use it for before you go ahead and choose the right approach.

Here is a simple code sample:

// Use the Framework API from versions 8.5 onwards
Ektron.Cms.Framework.User.UserManager uMgr = new Ektron.Cms.Framework.User.UserManager();
Ektron.Cms.User.UserTaxonomyCriteria criteria = new Ektron.Cms.User.UserTaxonomyCriteria();

// Get users based on taxonomy ID
//criteria.AddFilter(Ektron.Cms.User.UserTaxonomyProperty.Id, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, 98);

// Or get users based on Taxonomy Path
criteria.AddFilter(Ektron.Cms.User.UserTaxonomyProperty.Path, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo,
"\\UserTax");

List userList = uMgr.GetList(criteria);

Response.Write(userList.Count().ToString());

The above code uses the Ektron Framework API to get the information so you will need to be using Ektron version 8.5 or greater.

Geo IP lookup API in Ektron

A useful feature of Ektron CMS is the ability to target content at specific people based on their geographic location. This is commonly done within the Targeted Content widget.

However there are often times when you need the ability to do this in code outside of a Pagebuilder widget. Fortunately the Ektron API provides you with a simple way of determining where the user is coming from:

Ektron.Cms.UserLocationData userLocationInfo = Ektron.Cms.UserContext.GetLocationInfo("192.168.1.1");

if (userLocationInfo.CountryCode == "GB")
{
// User is from Great Britain
}

The simple example given above determines if a user resides in Great Britain or not by checking the CountryCode property of the UserLocationData object.  The GetLocationInfo() method takes a string parameter that holds the IP address that you want to look up.  Typically you would get this address by calling something like Request.UserHostAddress.

There are many other properties available from the UserLocationData object such as:

  • CountryName
  • City
  • Latitude
  • Longitude
  • Postalcode

The CMS makes use of three data files that are stored in your App_Data folder to get this information.  Those files are:

  • GeoIPDomain.dat
  • GeoIPOrg.dat
  • GeoLiteCity.dat

These data files are from an organisation called MaxMind so it is possible to update the data files from there and also to purchase a more complete file that contains advanced information (like what company a user works for).

Slow login to Ektron

I recently discovered a problem on a client’s site whereby it was taking a long time to login to the CMS. They had Active Directory integration enabled but we were able to rule that out as being the cause of the slowness by temporarily disabling it.

We also investigated the possibility that there may have been some plug-ins / extensions running that could be performing some kind of background task and slowing it down.  However this was not the case either. The problem did turn out to be related to plug-ins though…

Remember that from v8.0 Ektron introduced Extensions to replace the older plug-in technology. Plug-ins and Extensions allow you to write code modules that execute code following on from events that occur within the CMS. Such an event might be related to creating a user or deleting a content item.

There is a setting in the Ektron web.config file that turns the old plug-ins on or off:

<add key="ek_extensionServiceEnabled" value="true"/>

If you are on version 8.0 or greater then this setting should always be “false”.  Unbeknownst to me at the time, adding new content items was also running slowly. This was also due to this setting being set at “true”. Basically, the Ektron was looking for the old plug-ins and waiting for a set amount of time before giving up – hence the delay.

Setting this to “false” suddenly made adding content and logging in users much faster!