Domain Accounts

Domain Accounts

Domain Accounts

  • 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

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Security.Accounts.Account
  • Sitecore.Security.Domains.Domain
  • System.Collections.Generic.IEnumerable

Domain Accounts C# Web Control Code

//Alternative to Sitecore.Configuration.Factory.GetDomain(domainName);
Sitecore.Security.Domains.Domain domain = Sitecore.Security.Domains.Domain.GetDomain("Demo");
if (domain == null) return;

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

//The GetAccounts() method creates an IEnumerable object
System.Collections.Generic.IEnumerable<Sitecore.Security.Accounts.Account> accounts = domain.GetAccounts();
if (accounts == 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
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul);

foreach(Sitecore.Security.Accounts.Account account in accounts)
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
    output.Write("{0}&#58;&#160;{1}", account.AccountType.ToString(), "<b>" + account.Name + "</b>");
    output.RenderEndTag(); //Li
}

output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div


Domain Accounts C# Web Control Output

  • Role: demo\DemoRole
  • User: demo\Anonymous
  • User: demo\DemoUser1
  • User: demo\DemoUser2
  • User: demo\DemoUser3