Web.config Settings

Web.config Settings

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item
  • Sitecore.IO.FileUtil
  • System.Xml.XmlReader
  • System.Xml.XmlReaderSettings

Web.config Settings C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;
    
string filePath = Sitecore.IO.FileUtil.MapPath("/web.config");

System.Xml.XmlReaderSettings readerSettings = new System.Xml.XmlReaderSettings();
readerSettings.IgnoreComments = true;
readerSettings.IgnoreWhitespace = true;
System.Xml.XmlReader xmlRead = System.Xml.XmlReader.Create(filePath, readerSettings);

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("{0}", "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(); //

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", @"First ten <settings> nodes in Web.config");
output.RenderEndTag(); //P

int i = 0;
if (xmlRead.ReadToDescendant("setting"))
{
    do
    {
        i++;
        output.Write("{0}&#58;&#160;{1}", xmlRead["name"], "<b>" + xmlRead["value"] + "</b><br/>");
        //only show first 10 settings on page
        if (i >= 10) break;
    }
    while (xmlRead.ReadToNextSibling("setting"));
}
output.RenderEndTag(); //Div
xmlRead.Close();

Web.conf Settings C# Web Control Output

First ten <settings> nodes in Web.config

AliasesActive: true
AllowLogoutOfAllUsers: false
AppendQSToUrlRendering: true
Authentication.ClientSessionTimeout: 60
Authentication.DefaultMembershipProviderWildcard: %
Authentication.SaveRawUrl: false
Authentication.VirtualMembershipWildcard: *
Authentication.ClientPersistentLoginDuration: 180
AutomaticDataBind: false
AutomaticLockOnSave: false

Sources