protected
void
Page_Load(
object
sender, EventArgs e)
{
//if the url contains a virtual directory, the application virtual path will be replaced
//by the url of the current (default) site.
string
defaultSiteUrl = Telerik.Sitefinity.Multisite.MultisiteManager.GetManager().GetSites().FirstOrDefault(a => a.IsDefault).LiveUrl;
var liveUrl = SystemManager.CurrentContext.CurrentSite.LiveUrl;
var requestUrl = SystemManager.CurrentHttpContext.Request.Url.AbsoluteUri;
string
canonicalUrl = requestUrl;
if
(!liveUrl.Equals(defaultSiteUrl))
{
canonicalUrl = requestUrl.Replace(liveUrl, defaultSiteUrl);
}
this
.SetCanonicalMetaTag(canonicalUrl);
}
/// <summary>
/// Sets the canonical meta tag.
/// </summary>
/// <param name="href">The href.</param>
private
void
SetCanonicalMetaTag(
string
href)
{
HtmlLink canonicalLink =
new
HtmlLink();
canonicalLink.Attributes.Add(
"rel"
, CanonicalMetaTagSetter.CANONICAL);
canonicalLink.Attributes.Add(
"href"
, href);
this
.Page.Header.Controls.Add(canonicalLink);
}
private
const
string
CANONICAL =
"canonical"
;