Hi,
I am migrating my site from asp.net to umbraco and have now setup my pages to work without the .aspx extension.
Because the pages can still be shown if you add the .aspx extension, I would like to add a canonical tag which basically tells google that the two versions of the page are the same (thereby avoiding duplicate content issues.
The format of the tag needs to be
This means that if google was to find the .aspx version of the page it would index it as per the details in the canonical tag.
I would like to put this in my Master template so my question is what variable can I use to get the href portion of the tag above?
In ASP .NET / C# you can use the Request.Url.AbsoluteUri page property to get the full URL of the current page. There are also many other properties of Request.Url for getting host names etc.
The inline code did write the values out, however the markup was going before the opening tag and I couldn't figure out how to stop it.
In the end I created a user control with a literal control and the following code:
[code]
protected void Page_Load(object sender, EventArgs e)
{
string url = Request.Url.ToString();
if (url.ToLower().EndsWith(".aspx"))
{
url = url.Substring(0, url.Length - 5);
}
litCanonical.Text ="";
}
[/code]
This simply strips off the .aspx portion of my URL's so I won't run the risk of duplicate content in Google. I will probably extend it in the near future to allow me to override the default value with a value from my template.
How to get current URL for Canonical Tags
Hi,
I am migrating my site from asp.net to umbraco and have now setup my pages to work without the .aspx extension.
Because the pages can still be shown if you add the .aspx extension, I would like to add a canonical tag which basically tells google that the two versions of the page are the same (thereby avoiding duplicate content issues.
The format of the tag needs to be
This means that if google was to find the .aspx version of the page it would index it as per the details in the canonical tag.
I would like to put this in my Master template so my question is what variable can I use to get the href portion of the tag above?
Thanks,
Aaron
In ASP .NET / C# you can use the Request.Url.AbsoluteUri page property to get the full URL of the current page. There are also many other properties of Request.Url for getting host names etc.
See http://msdn.microsoft.com/en-us/library/system.web.httprequest.url.aspx
Also see http://www.mikesdotnetting.com/Article.aspx?ArticleID=29 for other methods.
Thanks for the quick reply Diplo.
I know about the Request.URL method but my question would be how can I access the value of that in my template?
Cheers
Aaron
Hi Aaron,
Add some inline c# code using <% and %> tags as you would in any asp.net application.
[code]<%
string url = Request.Url;
Response.Write(url);
%>
[/code]
Regards,
/Dirk
Thanks for all the responses.
The inline code did write the values out, however the markup was going before the opening tag and I couldn't figure out how to stop it.
In the end I created a user control with a literal control and the following code:
[code]
protected void Page_Load(object sender, EventArgs e)
{
string url = Request.Url.ToString();
if (url.ToLower().EndsWith(".aspx"))
{
url = url.Substring(0, url.Length - 5);
}
litCanonical.Text ="";
}
[/code]
This simply strips off the .aspx portion of my URL's so I won't run the risk of duplicate content in Google. I will probably extend it in the near future to allow me to override the default value with a value from my template.
is working on a reply...