Programming SEO – Ping

tortoise

Now that we have an RSS feed we can use the feed to ping the various RSS directories that are available on the Internet.  This will create links back to your site including links back to your inner pages, which are the best links you can get.

You also get the advantage of people searching for information on those sites, finding a link to your site, and eventually coming to your site.

Once again, there is code that has already been written about pinging from ASP.NET.  So I’m not going to bother republishing that content.  Here are some links you might be interested in looking at for the code:

Once you have your basic ping code set up, you’ll need to have your code fire it off.  As mentioned in one of the articles above, you’ll want to make sure you do this in a multi-threaded way.  But you’ll also want to make sure that you don’t ping too often, or you can get your site banned by some of the directories you are trying to notify.

In the code that I implemented, the articles have a time stamp for when they will be published.  So all I need to do in my code is see if there is an article that has been published since the last time I sent out the ping and send out a new ping if there is.

The site I implemented this on is on a web farm, which made the code a little more complicated than yours might need to be, but here’s what I wrote.

 

try
{
    if (Cache["rssDate"] == null)
        Cache["rssDate"] =
            Controller.GetRSS()[0].Launch_Date;
    if (Cache["lastRssDate"] == null)
        Cache.Add("lastRssDate",
            Controller.GetLastRssDate(),
            null,
            System.Web.Caching.Cache.NoAbsoluteExpiration,
            new TimeSpan(12, 0, 0),
            System.Web.Caching.CacheItemPriority.Normal,
            null);

    DateTime lastRssDate = (DateTime)(Cache["lastRssDate"]);

    DateTime mostRecentRssDate =
        (DateTime)(Cache["rssDate"]);
    if (Request.Url.Host.ToLower()
        .Contains("www.domain.com") &&
        mostRecentRssDate > lastRssDate)
    {
        // double check because we are on a
        // farm and don't want to ping twice
        Cache["rssDate"] =
            Controller.GetRSS()[0].Launch_Date;
        Cache.Add("lastRssDate",
            Controller.GetLastRssDate(),
            null,
            System.Web.Caching.Cache.NoAbsoluteExpiration,
            new TimeSpan(12, 0, 0),
            System.Web.Caching.CacheItemPriority.Normal,
            null);
        lastRssDate = (DateTime)(Cache["lastRssDate"]);
        mostRecentRssDate = (DateTime)(Cache["rssDate"]);

        if (mostRecentRssDate > lastRssDate)
        {
            Controller.SetLastRssDate(mostRecentRssDate);
            Cache["rssDate"] = mostRecentRssDate;
            Pinger.DoPings("Site Title",
                "http://www.domain.com/RSS.ashx");
        }
    }
}
catch (Exception)
{
}

Notice that I’m using the Cache object to store the last date so that I don’t have to retrieve it from the database, but I am storing the information in the database so that I can retrieve it from the other server(s).  rssDate stores the most recent date from the RSS feed and lastRssDate stores the last time the ping was sent out.

I placed this code in the Page_Load event handler of the master page of my site so that it would fire whenever a page on the site was accessed.  Since the site I placed this on gets over 1000 visitors a day, I figured this was sufficient.

Related Post

2 Responses to “Programming SEO – Ping”

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail

Bear