WebUtil Settings

WebUtil Settings

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Web.WebUtil
  • Sitecore.Data.Items.Item
  • Sitecore.StringUtil 

WebUtil Settings C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
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);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

if (Sitecore.Web.WebUtil.GetHostName() != null)
    output.Write("{0}&#58;&#160;{1}", "Server Host Name", "<b>" + Sitecore.Web.WebUtil.GetHostName() + "</b><br/>");
if (Sitecore.Web.WebUtil.GetHostIPAddress() != null)
    output.Write("{0}&#58;&#160;{1}", "Server Host IP Address", "<b>" + Sitecore.Web.WebUtil.GetHostIPAddress() + "</b><br/>");
if (Sitecore.Web.WebUtil.GetIISName() != null)
    output.Write("{0}&#58;&#160;{1}", "Server IIS Name", "<b>" + Sitecore.Web.WebUtil.GetIISName() + "</b><br/>");
if (Sitecore.Web.WebUtil.GetLoginCookieName() != null)
    output.Write("{0}&#58;&#160;{1}", "Login Cookie Name", "<b>" + Sitecore.Web.WebUtil.GetLoginCookieName() + "</b><br/>");

output.Write("{0}&#58;&#160;{1}", "Server Port Number", "<b>" + Sitecore.Web.WebUtil.GetPort().ToString() + "</b><br/>");
string rawUrl = string.Empty;
if (Sitecore.Web.WebUtil.GetRawUrl() != null)
{
    rawUrl = Sitecore.Web.WebUtil.GetRawUrl();
    output.Write("{0}&#58;&#160;{1}", "Raw URL", "<b>" + rawUrl + "</b><br/>");
    if (Sitecore.Web.WebUtil.NormalizeUrl(rawUrl) != null)
        output.Write("{0}&#58;&#160;{1}", "Normalized URL", "<b>" + Sitecore.Web.WebUtil.NormalizeUrl(rawUrl) + "</b><br/>");
    if (Sitecore.Web.WebUtil.GetFullUrl(rawUrl) != null)
        output.Write("{0}&#58;&#160;{1}", "Full URL", "<b>" + Sitecore.Web.WebUtil.GetFullUrl(rawUrl) + "</b><br/>");
    if (Sitecore.Web.WebUtil.ExtractFilePath(rawUrl) != null)
        output.Write("{0}&#58;&#160;{1}", "File Path", "<b>" + Sitecore.Web.WebUtil.ExtractFilePath(rawUrl) + "</b><br/>");
}

if (Sitecore.Web.WebUtil.GetRequestUri().UserInfo != null)
    output.Write("{0}&#58;&#160;{1}", "User Info", "<b>" + Sitecore.Web.WebUtil.GetRequestUri().UserInfo + "</b><br/>");
if (Sitecore.Web.WebUtil.GetSessionID() != null)
    output.Write("{0}&#58;&#160;{1}", "Session ID", "<b>" + Sitecore.Web.WebUtil.GetSessionID() + "</b><br/>");
if (Sitecore.Web.WebUtil.GetWebItemSource() != null)
    output.Write("{0}&#58;&#160;{1}", "Web Item Source", "<b>" + Sitecore.Web.WebUtil.GetWebItemSource() + "</b><br/>");
if (Sitecore.Web.WebUtil.GetBrowserCapabilities() != null)
    output.Write("{0}&#58;&#160;{1}", "Browser Capabilities", "<b>" + Sitecore.Web.WebUtil.GetBrowserCapabilities().ToString() + "</b><br/>");

output.Write("{0}&#63;&#160;{1}", "Is ASPX page", "<b>" + Sitecore.Web.WebUtil.IsOnAspxPage().ToString() + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Page is postback", "<b>" + Sitecore.Web.WebUtil.IsPostBack().ToString() + "</b>");
  
 output.RenderEndTag(); //Div


WebUtil Settings C# Web Control Output

Server Host Name: tic66
Server Host IP Address: 127.0.0.1
Server IIS Name: bef47b8f87531257c47f24686dc60ebf
Login Cookie Name: tic6680_sitecore_username
Server Port Number: 80
Raw URL: /en/Developers/SitecoreSites/SiteManagement/WebUtilSettings
Normalized URL: /en/Developers/SitecoreSites/SiteManagement/WebUtilSettings
Full URL: http://tic66/en/Developers/SitecoreSites/SiteManagement/WebUtilSettings
File Path: /en/Developers/SitecoreSites/SiteManagement/WebUtilSettings
User Info: 
Session ID: gwua2bylhh1spsu1a5mznh3r
Web Item Source: /home
Browser Capabilities: System.Web.Mobile.MobileCapabilities
Is ASPX page? False
Page is postback? False