User Properties

User Properties

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item
  • Sitecore.Security.Accounts.User
  • Sitecore.SecurityModel.UserRuntimeSettings

User Properties

  • AccountType retrieves whether the account is a user or role
  • Delegation retrieves the delegation for the account
  • Description retrieves the description assigned to the user account
  • DisplayName retrieves the display name assigned to the user account
  • Domain retrieves the name of the security domain associated with the user account
  • Identity retrieves the identity of the principal
  • IsAdministrator retrieves whether or not the user is an administrator account
  • LocalName retrieves the name of the local
  • Name retrieves the name of the role
  • IsAuthenticated retrieves whether the account is currently authenticated (logged on) to the system
  • IsVirtual retrieves whether the account is logged on as a virtual user

User Account Restrictions

  • The name of the user account cannot be updated once the account is created
  • User accounts cannot be moved to a different security domain once the account is created

C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

string targetUserName = "Extranet\\Demo";
Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(targetUserName, true);

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.Write("C# Web Control Real-time Output");

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + user.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Display Name", "<b>" + user.DisplayName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Local Name", "<b>" + user.LocalName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Account Type", "<b>" + user.AccountType.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Description", "<b>" + user.Description + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Domain", "<b>" + user.GetDomainName() + "</b><br/>");

Sitecore.Security.Domains.Domain domain = user.Domain;
if (domain != null)
    output.Write("{0}&#58;&#160;{1}", "Account Prefix", "<b>" + domain.AccountPrefix + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Domain Name", "<b>" + domain.Name + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Everyone Role Name", "<b>" + domain.EveryoneRoleName + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Anonymous User Name", "<b>" + domain.AnonymousUserName + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Anonymous User Email Pattern", "<b>" + domain.AnonymousUserEmailPattern + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Member Pattern", "<b>" + domain.MemberPattern + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Ensure Anonymous User", "<b>" + domain.EnsureAnonymousUser.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Is Default", "<b>" + domain.IsDefault.ToString() + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Locally Managed", "<b>" + domain.LocallyManaged.ToString() + "</b><br/>");

Sitecore.Security.Accounts.UserDelegation delegation = user.Delegation;
if (delegation != null)
    output.Write("{0}&#63;&#160;{1}", "Can Manage Domain", "<b>" + delegation.CanManage(domain).ToString() + "</b><br/>");

System.Security.Principal.IIdentity identity = user.Identity;
if (identity != null)
    output.Write("{0}&#58;&#160;{1}", "Identity Name", "<b>" + identity.Name + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Authentication Type", "<b>" + identity.AuthenticationType + "</b><br/>");
    output.Write("{0}&#63;&#160;{1}", "Identity Is Authenticated", "<b>" + identity.IsAuthenticated.ToString() + "</b><br/>");

output.Write("{0}&#63;&#160;{1}", "Is Administrator", "<b>" + user.IsAdministrator.ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Is Authenticated", "<b>" + user.IsAuthenticated.ToString() + "</b><br/>");

Sitecore.SecurityModel.UserRuntimeSettings settings = user.RuntimeSettings;
if(settings != null)
    output.Write("{0}&#63;&#160;{1}", "Is Virtual", "<b>" + settings.IsVirtual.ToString() + "</b>");

output.RenderEndTag(); //Div

User Properties C# Web Control Output

Name: Extranet\Demo
Display Name: Extranet\Demo
Local Name: Demo
Account Type: User
Description: User
Domain: extranet
Account Prefix: extranet\
Domain Name: extranet
Everyone Role Name: extranet\Everyone
Anonymous User Name: extranet\Anonymous
Anonymous User Email Pattern: 
Member Pattern? extranet\*
Ensure Anonymous User? True
Is Default? False
Locally Managed? False
Can Manage Domain? True
Identity Name: Extranet\Demo
Authentication Type: 
Identity Is Authenticated? True
Is Administrator? False
Is Authenticated? True
Is Virtual? False