How to Add "nofollow" to SiteMapProvider Links in Repeater (ASP.NET)
December 11, 2010
Add rel="nofollow" tags to ASP.NET SiteMap links that are bound to a Repeater control.
Here's how you can add "nofollow" tags to links generated by a Sitemap file that is bound to an ASP.NET Repeater control using a SiteMapDataSource.
I'm currently using this technique for the footer links of GotKnowHow.com, so if you View Source of the html, you will notice that the Contact, Privacy and Terms links all have: rel="nofollow". This is typically considered good practice in terms of SEO. Since those links are on every page, and are links to non-essential pages in terms of SEO, I don't need them to be ranked or want those links to take away from other more important internal links on the site.
Here's what I did to add nofollow to SiteMapDataSource links within a Repeater control:
siteMapNode url="~/info/privacy.aspx" title="Privacy" description="" IsNoFollow="true"
2. I then added an ItemDataBound event to the Repeater, that looks for "IsNoFollow" within the SiteMapNode for each bound node, so that the rel="nofollow" attribute is added to the tagged HyperLinks within the Repeater control.
Here's the code for the ItemDataBound event:
protected void FooterRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
SiteMapNode node = e.Item.DataItem as SiteMapNode;
string noFollow = node["IsNoFollow"];
if (!string.IsNullOrEmpty(noFollow) && noFollow == "true")
HyperLink hlnkFooter = (HyperLink)e.Item.FindControl("FooterHyperLink");
To see the full ASP.NET / C# example code, download the .zip file below.
SiteMap - NoFollow Links in Repeater Example.zip