UrlOptions Defaults

UrlOptions Defaults

URLOptions

  • AddAspxExtension is used to include or exclude the .aspx extension in URLs (true or false). If set to false, use IIS7 and configure the application pool for Integrated Mode to ensure that ASP.NET uses Sitecore to process the request
  • AlwaysIncludeServerUrl is used to include the HTTP protocol and domain name in friendly URLs (true or false)
  • EncodeNames is used to encode names in paths according to the following entries in web.config

     /configuration/sitecore/encodeNameReplacements/replace

  • GetType is used to display the link provider
  • LanguageEmbedding is used to include the language in the URL (always, never, or asNeeded). When set to asNeeded, Sitecore includes the language in the URL if it cannot determine the context site from the incoming HTTP request, if that HTTP request does not include a cookie that specifies a language, or if the language of the linked item differs from the context language
  • LanguageLocation is to specify language at the beginning of the URL path or use the sc_lang URL query string parameter (filePath or queryString)
  • ShortenUrls is used to shorten URLs according to the Sitecore.Sites.Site
  • Site is used to get or set the site
  • UseDisplayName is used to specify that item display names or item names are used when constructing URLs (true or false). If set to true, different languages can have different URLs for the same content item
  • SiteResolving is used to indicate if site resolving is enabled

SiteResolving

  • GetItemUrl does not implement this setting
  • Use the following code as a workaround

Sitecore.Data.Items.Item item = Sitecore.Context.Item; Sitecore.Links.UrlOptions urlOptions = (Sitecore.Links.UrlOptions) Sitecore.Links.UrlOptions.DefaultOptions.Clone(); urlOptions.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving; string url = Sitecore.Links.LinkManager.GetItemUrl(item,urlOptions);

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item
  • Sitecore.Links.UrlOptions

UrlOptions Defaults Configuration Settings

  • <linkManager defaultProvider="sitecore">
    • <providers>
      • <clear/>
        • <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="true" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="always" languageLocation="filePath" shortenUrls="true" useDisplayName="false"/>

UrlOptions Defaults 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);
//using &#58; for colon and &#63; for question mark and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

string addASPXExtension = Sitecore.Links.UrlOptions.DefaultOptions.AddAspxExtension.ToString();
string alwaysIncludeServer = Sitecore.Links.UrlOptions.DefaultOptions.AlwaysIncludeServerUrl.ToString();
string encodeNames = Sitecore.Links.UrlOptions.DefaultOptions.EncodeNames.ToString();
string getType = Sitecore.Links.UrlOptions.DefaultOptions.GetType().ToString();
string urlLanguage = Sitecore.Links.UrlOptions.DefaultOptions.Language.ToString();
string languageEmbedding = Sitecore.Links.UrlOptions.DefaultOptions.LanguageEmbedding.ToString();
string languageLocation = Sitecore.Links.UrlOptions.DefaultOptions.LanguageLocation.ToString();
string shortenUrls = Sitecore.Links.UrlOptions.DefaultOptions.ShortenUrls.ToString();
string siteName = Sitecore.Links.UrlOptions.DefaultOptions.Site.Name;
string siteResolving = Sitecore.Links.UrlOptions.DefaultOptions.SiteResolving.ToString();
string useDisplayName = Sitecore.Links.UrlOptions.DefaultOptions.UseDisplayName.ToString();

//using &#58; for colon and &#160; for space
 output.Write("{0}&#63;&#160;{1}", "AddAspxExtension", "<b>" + addASPXExtension + "</b><br/>");
 output.Write("{0}&#63;&#160;{1}", "AlwaysIncludeServerUrl", "<b>" + alwaysIncludeServer + "</b><br/>");
 output.Write("{0}&#63;&#160;{1}", "EncodeNames", "<b>" + encodeNames + "</b><br/>");
 output.Write("{0}&#58;&#160;{1}", "GetType", "<b>" + getType + "</b><br/>");
 output.Write("{0}&#58;&#160;{1}", "Language", "<b>" + urlLanguage + "</b><br/>");
 output.Write("{0}&#58;&#160;{1}", "LanguageEmbedding", "<b>" + languageEmbedding + "</b><br/>");
 output.Write("{0}&#58;&#160;{1}", "LanguageLocation", "<b>" + languageLocation + "</b><br/>");
 output.Write("{0}&#63;&#160;{1}", "ShortenUrls", "<b>" + shortenUrls + "</b><br/>");
 output.Write("{0}&#58;&#160;{1}", "Site.Name", "<b>" + siteName + "</b><br/>");
 output.Write("{0}&#63;&#160;{1}", "SiteResolving", "<b>" + siteResolving + "</b><br/>");
 output.Write("{0}&#63;&#160;{1}", "UseDisplayName", "<b>" + useDisplayName + "</b>");
 output.RenderEndTag(); //Div


UrlOptions Default C# Web Control Output

AddAspxExtension? False
AlwaysIncludeServerUrl? True
EncodeNames? True
GetType: Sitecore.Links.UrlOptions
Language: en
LanguageEmbedding: Always
LanguageLocation: FilePath
ShortenUrls? True
Site.Name: website
SiteResolving? False
UseDisplayName? False

Sources