Context Domain

Context Domain

Context Domain

  • The Sitecore security domain associated with the context site
  • Presentation components that use security APIs, such as registration and login forms, usually access the context domain

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Security.Domains.Domain

Context Domain C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == 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 : for colon and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul);

Sitecore.Security.Domains.Domain domain = Sitecore.Context.Domain;
string name = domain.Name;
string isDefault = domain.IsDefault.ToString();

if (!string.IsNullOrEmpty(name))
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
    output.Write("{0}&#58;&#160;{1}", "Context Domain", "<b>" + name + "</b>");
    output.RenderEndTag();
}

if (!string.IsNullOrEmpty(isDefault))
{
    output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
    //using &#63; for question mark and &#160; for space
    output.Write("{0}&#63;&#160;{1}", "Is Default Domain", "<b>" + isDefault + "</b>");
    output.RenderEndTag();
}
output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div


Context Domain C# Web Control Output

  • Context Domain: extranet
  • Is Default Domain? False