Dynamic URLs

Dynamic URLs

Dynamic URLs

  • The address of an internal web page that is generated by a database-driven Web site
  • A page address that contains a GUID for the destination item and other characters
  • Converted to a relative path or absolute URL in the HTML markup by the system
  • Use GetDynamicUrl method in LinkManager class to access
  • Use LinkManager element in web.config to configure whether system generates relative path or absolute URL in HTML markup

Dynamic URLs and SEO

  • Some Search Engines do not index Dynamic URLs
  • Other Search Engines only index dynamic URLs when the page contains targeted content

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item
  • Sitecore.Data.Managers.LanguageManager
  • Sitecore.Globalization.Language
  • Sitecore.Links.LinkManager
  • Sitecore.Links.LinkUrlOptions

Dynamic URLs C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;
Sitecore.Links.LinkUrlOptions linkUrlOptions = new Sitecore.Links.LinkUrlOptions();
Sitecore.Globalization.Language language = Sitecore.Data.Managers.LanguageManager.DefaultLanguage;
if (language == null) return;
linkUrlOptions.Language = language;

string dynamicUrl1 = Sitecore.Links.LinkManager.GetDynamicUrl(item);
string dynamicUrl2 = Sitecore.Links.LinkManager.GetDynamicUrl(item, linkUrlOptions);
if(!string.IsNullOrEmpty(dynamicUrl1) || !string.IsNullOrEmpty(dynamicUrl2)) 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.Write("{0}&#58;&#160;{1}", "Dynamic Url Without Setting URLOptions", "<b>" + dynamicUrl1 + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Dynamic Url With URLOption for Language Embedding", "<b>" + dynamicUrl2 + "</b>");
output.RenderEndTag();  //Div

Sources