Get URLs

Get URLs

Sitecore URLs

  • Used as a record locator for the appropriate item in the Content Tree
  • Do not correspond directly to files on disk
  • Correspond to content items in the database
  • Items reference ASP.NET and XSL presentation components implemented as files on disk

The Page Creation Process

  • Sitecore builds pages on the fly; they do not pre-exist as .html or .aspx files
  • The Uniform Resource Locator (URL) tells Sitecore which page to build
  • The HTTP request is processed by the HttpRequestBegin pipeline; one of the last processor steps resolves the item in the Content Tree
  • The presentation components are processed by the RenderLayout pipeline, which returns markup (XHTML typically)

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Links.LanguageEmbedding
  • Sitecore.Links.LanguageLocation
  • Sitecore.Links.LinkManager
  • Sitecore.Links.UrlOptions
  • Sitecore.Web.WebUtil

URLs C# Web Control Code

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

Sitecore.Links.UrlOptions urlOptions = Sitecore.Links.UrlOptions.DefaultOptions.Clone() as Sitecore.Links.UrlOptions;
if (urlOptions == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.Write("C# Web Control Real-time Output");

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
//using : for colon and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

urlOptions.LanguageEmbedding = Sitecore.Links.LanguageEmbedding.Always;
urlOptions.LanguageLocation = Sitecore.Links.LanguageLocation.FilePath;
urlOptions.UseDisplayName = false;

string url = Sitecore.Links.LinkManager.GetItemUrl(item, urlOptions);
string fullUrl = Sitecore.Web.WebUtil.GetFullUrl(url);
string filePath = Sitecore.Web.WebUtil.ExtractFilePath(fullUrl);

output.Write("{0}&#58;&#160;{1}", "URL", "<b>" + url + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Full URL", "<b>" + fullUrl + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "File Path", "<b>" + filePath + "</b>");

output.RenderEndTag(); //Div

URLs C# Web Control Output

URL: http://tic66/en/Developers/ContentDisplay/LinkManagement/GetURLs
Full URL: http://tic66/en/Developers/ContentDisplay/LinkManagement/GetURLs
File Path: en/Developers/ContentDisplay/LinkManagement/GetURLs