I had the opportunity to work with enabling the display of the Common Name in Community Server today and wanted to ramble on some of the aspects involved. The user's Common Name field, if enabled, would be displayed on the User Welcome control, on the user profile page and a few other site locations.
EnableDisplayName is a property in the SiteSettings Component and is set to false by default. It can be set in Administration->Settings->General Site Settings. I spent forever looking for it because I was looking under Membership, but it's in there.
Setting the EnableDisplayName to true gives the user the option of displaying his or her Common Name field, it doesn't automatically display the user's common name. The user has the final say in that. The area circled below in the user's Edit Profile page is visible only when the site EnableDisplayName property is set to true, otherwise it is not visible.
The circled area is displayed or hidden based on a Chameleon Conditional Control using a SiteSettingsPropertyValueComparison CSControl, which as its name implies, checks the value of a SiteSettings property. (Pretty cool control, and is used pretty extensively in CS.Web.)
<DisplayConditions><CSControl:SiteSettingsPropertyValueComparison runat="server" ComparisonProperty="EnableDisplayNames" Operator="IsSetOrTrue" /></DisplayConditions>
At the user level, EnableDisplayName is a property of the User class and stored as an Extended User Attribute.
\source\Components\Components\User.cs
public bool EnableDisplayName
{
get { return GetBool("EnableDisplayName",false);}
set{ SetExtendedAttribute("EnableDisplayName", value.ToString());}
}
When User.DisplayName is requested for display, like in the User Welcome control above, both SiteSettings.EnableDisplayName and the user's EnableDisplayName property are tested and must be set to true for the common name to display.
public string DisplayName {
get {
string cn = null;
if(CSContext.Current.SiteSettings.EnableDisplayNames && this.EnableDisplayName && this.HasProfile)
cn = this.Profile.CommonName;
if (Globals.IsNullorEmpty(cn))
return this.username;
return cn;
}
}
Thus endeth the ramble.