ASP.NET Tutorial: Add rel=”nofollow noopener noreferrer” to External Links in Sitecore

In many of the solutions we develop with Sitecore, for external links, we need to add the nofollow noopener noreferrer values ​​of the rel attribute for the <a> tags to have a final markup like this.

Markup
 

These values allow us to

  • nofollow: Tells search engines not to follow the link.
  • noopener: Stops the new page from controlling the original page.
  • noreferrer: Hides the link source from the new page.

With this goal in mind, we are going to see in this tutorial a proposal to add the rel attribute in an elegant way in our solution.

Sitecore Link Attributes Settings Item

The goal will be to add the values ​​nofollow, noopener noreferrer to the attribute, but it does not necessarily have to be for all external links. Exceptions could surely be established according to the client’s needs. Keeping these considerations in mind, in Sitecore, we can define the following template, with its respective standard values.

Template

Template

Standard Values

Standard Values:

The logic on the .NET side

To obtain the attribute and its values ​​to add to external links, we will use a helper that allows sending the URL to be analyzed as a parameter and returning the expected attribute or an empty string from a view.

C# Code

In the helper, we will have to obtain the values ​​of the settings item specified above, and to have a better performance of this solution, we will add the setting values to the cache to obtain them quickly later.

View code

From the view of a component, we can have something like this.

Note. For this example, we assume that the Model object has the attributes of a General Link, that is, the URL and the Target.

Thanks for reading!

ASP.NET 8.0.7 Hosting Recommendation

ASP.NET is a powerful platform for creating web applications and services. You must be comfortable with JavaScript, HTML, CSS, and C# before developing a web application in ASP.NET. On the market, there are thousands of web hosting companies providing ASP.NET Hosting. But, only very few web hosting companies could provide high quality ASP.NET hosting solution. ASP.NET is the best development language in Windows platform, which is released by Microsoft and widely used to build all types of dynamic Web sites and XML Web services. With this article, we’re going to help you to find the best ASP.NET Hosting solution in Europe based on reliability, features, price, performance and technical support. After we reviewed about 30+ ASP.NET hosting providers in Europe, our Best ASP.NET Hosting Award in Europe goes to HostForLIFE.eu, one of the fastest growing private companies and one of the most reliable hosting providers in Europe.

You may also like...

Popular Posts