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.


Other Related Items:

Control Arm Upper RightControl Arm Upper RightControl Arm Upper Right W/ Ball Joint
Bubble Boy [VHS]Bubble Boy [VHS]Innocuous, innocent, and somewhat idiotic, Disney's bubbleheaded road-movie comedy plays as a farcical remake of the 1976 cult TV-movie melodrama The ... Read More >
Return of the Dragon [VHS]Return of the Dragon [VHS]Bruce Lee wrote and directed Return of the Dragon, his third film, a mix of hard-edged kung fu and goofy humor. Once again he plays the country boy wh... Read More >

If you're new here, you may want to subscribe to the mailing list to get notifications of new post and a virtual tour of past topics. Thanks for visiting!

Related Post

2 Responses to “Programming SEO – Ping”

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor