Domain Users

Domain Users

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil
  • Sitecore.Security.Accounts.Role
  • Sitecore.Security.Accounts.User
  • Sitecore.Security.Domains.Domain
  • System.Collections.Generic.IEnumerable

Domain Users C# Web Control Code

Sitecore.Security.Domains.Domain domain = Sitecore.Configuration.Factory.GetDomain("demo");
Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (domain == null || item == null) return;

System.Collections.Generic.IEnumerable<Sitecore.Security.Accounts.Role> roles = domain.GetRoles();
System.Collections.Generic.IEnumerable<Sitecore.Security.Accounts.User> users = domain.GetUsers();
if (roles == null || users == null) return;

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

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

foreach (Sitecore.Security.Accounts.User user in users)
{
    Sitecore.MainUtil.Out("Name: <b>" + user.Name + "</b>");
    Sitecore.MainUtil.Out("Description: <b>" + user.Description + "</b>");
    Sitecore.MainUtil.Out("Display Name: <b>" + user.DisplayName + "</b>");
    Sitecore.MainUtil.Out("Account Type: <b>" + user.AccountType.ToString() + "</b>");
    Sitecore.MainUtil.Out("Domain: <b>" + user.Domain.ToString() + "</b>");
    Sitecore.MainUtil.Out("Delegation: <b>" + user.Delegation.ToString() + "</b>");
    Sitecore.MainUtil.Out("Identity: <b>" + user.Identity.ToString() + "</b>");
    Sitecore.MainUtil.Out("Is Administrator?: <b>" + user.IsAdministrator.ToString() + "</b>");
    Sitecore.MainUtil.Out("Is Authenticated?: <b>" + user.IsAuthenticated.ToString() + "</b>");
    Sitecore.MainUtil.Out("Local Name: <b>" + user.LocalName + "</b>");
    Sitecore.MainUtil.Out("Client Language: <b>" + user.Profile.ClientLanguage + "</b>");
    Sitecore.MainUtil.Out("Comment: <b>" + user.Profile.Comment + "</b>");
    Sitecore.MainUtil.Out("Content Language: <b>" + user.Profile.ContentLanguage.ToString() + "</b>");
    Sitecore.MainUtil.Out("Culture: <b>" + user.Profile.Culture.ToString() + "</b>");
    Sitecore.MainUtil.Out("Email: <b>" + user.Profile.Email + "</b>");
    Sitecore.MainUtil.Out("Full Name: <b>" + user.Profile.FullName + "</b>");
    Sitecore.MainUtil.Out("Icon: <b>" + user.Profile.Icon + "</b>");
    Sitecore.MainUtil.Out("Is Anonymous?: <b>" + user.Profile.IsAnonymous.ToString() + "</b>");
    Sitecore.MainUtil.Out("Properties Modified?: <b>" + user.Profile.IsDirty.ToString() + "</b>");
    Sitecore.MainUtil.Out("Last Activity Date: <b>" + user.Profile.LastActivityDate.ToString() + "</b>");
    Sitecore.MainUtil.Out("Last Profile Update: <b>" + user.Profile.LastUpdatedDate.ToString() + "</b>");
    Sitecore.MainUtil.Out("Domains To Manage: <b>" + user.Profile.ManagedDomainNames.ToString() + "</b>");
    Sitecore.MainUtil.Out("Portrait: <b>" + user.Profile.Portrait + "</b>");
    Sitecore.MainUtil.Out("Profile Item ID: <b>" + user.Profile.ProfileItemId + "</b>");
    Sitecore.MainUtil.Out("Regional ISO Code: <b>" + user.Profile.RegionalIsoCode + "</b>");
    Sitecore.MainUtil.Out("Start URL: <b>" + user.Profile.StartUrl + "</b>");
    Sitecore.MainUtil.Out("State: <b>" + user.Profile.State + "</b>");
    Sitecore.MainUtil.Out("User Name: <b>" + user.Profile.UserName + "</b>");

    foreach (Sitecore.Security.Accounts.Role role in roles)
    {
        string userMember = user.IsInRole(role).ToString();
        Sitecore.MainUtil.Out("Role: <b>" + role.DisplayName + "</b>");
    }
    //alternative to output.Write("<hr/>");
    Sitecore.MainUtil.Out("<hr/>");
}
output.RenderEndTag(); //Div


Domain Users C# Web Control Output

 

Name: demo\Anonymous
Description: User
Display Name: demo\Anonymous
Account Type: User
Domain: demo
Delegation: Sitecore.Security.Accounts.UserDelegation
Identity: Sitecore.Security.Principal.SitecoreIdentity
Is Administrator?: False
Is Authenticated?: False
Local Name: Anonymous
Client Language: 
Comment: 
Content Language: 
Culture: en-US
Email: 
Full Name: 
Icon: 
Is Anonymous?: True
Properties Modified?: False
Last Activity Date: 10/7/2014 6:18:50 AM
Last Profile Update: 12/8/2012 6:59:17 AM
Domains To Manage: 
Portrait: people/16x16/user1.png
Profile Item ID: 
Regional ISO Code: 
Start URL: 
State: 
User Name: demo\Anonymous
Role: demo\DemoRole

 

 

 

Name: demo\DemoUser1
Description: User
Display Name: demo\DemoUser1
Account Type: User
Domain: demo
Delegation: Sitecore.Security.Accounts.UserDelegation
Identity: Sitecore.Security.Principal.SitecoreIdentity
Is Administrator?: False
Is Authenticated?: False
Local Name: DemoUser1
Client Language: 
Comment: demo user
Content Language: 
Culture: en-US
Email: demouser1@theinsidecorner.com
Full Name: Demo User One
Icon: 
Is Anonymous?: True
Properties Modified?: False
Last Activity Date: 10/7/2014 6:18:50 AM
Last Profile Update: 12/8/2012 6:54:55 AM
Domains To Manage: 
Portrait: people/16x16/user1.png
Profile Item ID: {AE4C4969-5B7E-4B4E-9042-B2D8701CE214}
Regional ISO Code: 
Start URL: 
State: 
User Name: demo\DemoUser1
Role: demo\DemoRole

 

 

 

Name: demo\DemoUser2
Description: User
Display Name: demo\DemoUser2
Account Type: User
Domain: demo
Delegation: Sitecore.Security.Accounts.UserDelegation
Identity: Sitecore.Security.Principal.SitecoreIdentity
Is Administrator?: False
Is Authenticated?: False
Local Name: DemoUser2
Client Language: 
Comment: demo user
Content Language: 
Culture: en-US
Email: demouser2@theinsidecorner.com
Full Name: Demo User Two
Icon: 
Is Anonymous?: True
Properties Modified?: False
Last Activity Date: 10/7/2014 6:18:50 AM
Last Profile Update: 12/8/2012 6:55:37 AM
Domains To Manage: 
Portrait: people/16x16/user1.png
Profile Item ID: {AE4C4969-5B7E-4B4E-9042-B2D8701CE214}
Regional ISO Code: 
Start URL: 
State: 
User Name: demo\DemoUser2
Role: demo\DemoRole

 

 

 

Name: demo\DemoUser3
Description: User
Display Name: demo\DemoUser3
Account Type: User
Domain: demo
Delegation: Sitecore.Security.Accounts.UserDelegation
Identity: Sitecore.Security.Principal.SitecoreIdentity
Is Administrator?: False
Is Authenticated?: False
Local Name: DemoUser3
Client Language: 
Comment: demo user
Content Language: 
Culture: en-US
Email: demouser3@theinsidecorner.com
Full Name: Demo User Three
Icon: 
Is Anonymous?: True
Properties Modified?: False
Last Activity Date: 10/7/2014 6:18:50 AM
Last Profile Update: 12/8/2012 6:56:30 AM
Domains To Manage: 
Portrait: people/16x16/user1.png
Profile Item ID: {AE4C4969-5B7E-4B4E-9042-B2D8701CE214}
Regional ISO Code: 
Start URL: 
State: 
User Name: demo\DemoUser3
Role: demo\DemoRole

Notes

  • A security domain named demo was created on this site
  • A role named DemoRole was created in the demo security domain
  • Three user accounts named DemoUser1, DemoUser2, and DemoUser3 were created in the demo security domain
  • The anonymous user was added to the demo security domain automatically by Sitecore