Welcome to TechNet Blogs Sign in | Join | Help

Adjusting the MOSS ROBOTS meta tag for 3rd party search engines

When developing a public facing website using the publishing features of MOSS it might be required to emit a ROBOTS meta tag that prevents internet search engines from indexing specific pages.

The standard RobotsMetaTag control included in WSS generates the following tag:

<META NAME="ROBOTS" CONTENT="NOHTMLINDEX">

Unfortunatelly most search engines do not understand the NOHTMLINDEX content value but a value of NOINDEX. To resolve this it is required to replace the RobotsMetaTag control in the master page with a custom control that emits the correct value.

The following code will do this:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using Microsoft.SharePoint;
using System.Web.UI;

namespace StefanG.MossControls
{
    public class RobotsMetaTag : Microsoft.SharePoint.WebControls.RobotsMetaTag
    {
        protected override void Render(HtmlTextWriter writer)
        {
            SPWeb web = GetContextWeb(HttpContext.Current);
            if (web.ASPXPageIndexed == false)
            {
                writer.Write("<META NAME=\"ROBOTS\" CONTENT=\"NOHTMLINDEX,NOINDEX\"/>");
            }
        }
    }
}

Here are the required steps to implement this:

  1. compile the above code into a separate DLL (e.g. RobotsMetaTag.dll)
  2. if signed add the DLL to the GAC - otherwise copy it into the bin directory of your web application
  3. add the control to the save controls list in the web.config

          <SafeControl Assembly="RobotsMetaTag" Namespace="StefanG.MossControls" TypeName="*" Safe="True" />

    (if the DLL is in the GAC ensure to add the strong assembly name instead with version and public key token).
  4. Open the master page in SharePoint designer and register your DLL:

          <%@ Register TagPrefix="StefanG" Namespace="StefanG.MossControls" Assembly="RobotsMetaTag" %>

    (if the DLL is in the GAC ensure to add the strong assembly name instead with version and public key token).
  5. replace the following tag:

          <SharePoint:RobotsMetaTag runat="server"/>

    with this:

          <StefanG::RobotsMetaTag runat="server"/>

 

Published Tuesday, June 19, 2007 2:01 PM by Stefan_Gossner

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Mike Walsh's WSS and more - WSS FAQ additions and changes LX - 18th - 24th June 2007

Monday, September 24, 2007 2:22 PM by Nicolas Roberge

# re: Adjusting the MOSS ROBOTS meta tag for 3rd party search engines

Is there a way to avoid Sharepoint Designer warning us that we are missing the original       <SharePoint:RobotsMetaTag runat="server"/> tag?

Monday, October 22, 2007 6:42 AM by SharePoint, SharePoint and stuff

# SharePoint Kaffeetasse 25

HotFix Security Hotfix MS07-059 Artikel zum Lesen Why SharePoint Server is Terrible Dazu der Kommentar

Monday, April 07, 2008 4:50 PM by Gael Duhamel

# re: Adjusting the MOSS ROBOTS meta tag for 3rd party search engines

Hi Stefan,

Why do you not use a control adapter instead of custom control? Is it for performance improvment?

Gael

Tuesday, April 08, 2008 4:22 AM by Stefan_Gossner

# re: Adjusting the MOSS ROBOTS meta tag for 3rd party search engines

Hi Gael,

nice idea! You are right: this would be the better solution.

I will post it in a minute as a new blog entry.

Cheers,

Stefan

Tuesday, April 08, 2008 4:37 AM by Stefan Goßner

# Adjusting the MOSS ROBOTS meta tag for 3rd party search engines - using a Control Adapter

When developing a public facing website using the publishing features of MOSS it might be required to

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker