Role Properties

Role Properties

Role Properties

  • AccountType retrieves whether the account is a user or role
  • Description retrieves the description assigned to the role
  • DisplayName retrieves the display name assigned to the role
  • Domain retrieves the name of the security domain associated with the role
  • Everyone retrieves whether or not the role is a member of the Everyone role
  • IsGlobal retrieves whether or not the role is global
  • LocalName retrieves the name of the local
  • Name retrieves the name of the role

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item
  • Sitecore.Security.Accounts.Role
  • Sitecore.StringUtil

Role Properties C# Web Control Code

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

string targetRoleName = "Sitecore\\Author";
Sitecore.Security.Accounts.Role role = Sitecore.Security.Accounts.Role.FromName(targetRoleName);
if (role == 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);
string itemName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", itemName);
output.RenderEndTag(); //P

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul);
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}: {1}", "AccountType", role.AccountType.ToString());
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}: {1}", "Description", role.Description);
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}: {1}", "DisplayName", role.DisplayName);
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}: {1}", "Domain", role.Domain.ToString());
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}? {1}", "IsEveryone", role.IsEveryone.ToString());
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}? {1}", "IsGlobal", role.IsGlobal.ToString());
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}: {1}", "LocalName", role.LocalName);
output.RenderEndTag();

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}: {1}", "Name", role.Name);
output.RenderEndTag(); //Li
output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div


Role Properties C# Web Control Output

  • AccountType: Role
  • Description: Role
  • DisplayName: Sitecore\Author
  • Domain: sitecore
  • IsEveryone? False
  • IsGlobal? False
  • LocalName: Sitecore\Author
  • Name: Sitecore\Author

Sources