How Trackbacks, Pingbacks, and Pings work

Topics: ASP.NET 2.0
Feb 9, 2009 at 9:26 PM
Edited Feb 10, 2009 at 3:34 AM
I haven't been blogging for very long so these three concepts were difficult for me to understand, and even more difficult to figure out how and if they were working. I haven't got it all figured out, but I thought I'd share what I have learned. If anyone wants to add to this it can become a great resource for a lot of other people who I know are having difficulties with this as well.

To enable/disable Trackbacks and/or PingBacks go to Admin->Settings->Advanced Settings
Sending Trackbacks and/or Pingbacks will allow you to leave a comment on another persons blog with a link back to your post
Receiving Trackbacks and/or Pingbacks will allow others to leave a comment on your blog with a linkback to their blog


Trackbacks

What it's for:
Say you are browsing a blog called BillysAwesomeBlog and he wrote a really an interesting post about BlogEngine which inspires you to write a post about his post. The trackback should leave a comment on BillysAwesomeBlog notifying all who view it that you have written an articles based on his with a link back to your site.

In short
1. You come across an interesting post which you would like to write or expand upon
2. You write about that post, referencing the blog via url in your post
3. When you add or update your post, it should leave a comment in his comment section that links back to your post

How it works in Blogengine:

Sending

When you insert or update a post, Blogengine looks for all the absolute urls in your post (Ones containing http), and first tries to send a trackback to those addresses. If the trackback fails, it will then try and send a pingback.

Ex:

Absolute url:  http://www.somesite.com/somearticles/12312/blogging.html   [Will Invoke Trackback or PingBack]
Relative url:   /somearticles/12312/blogging.html   [DOES NOT Invoke Trackback or PingBack]

[For Dev Testing only]
When testing on your local server, you need to disable the IsLocal condition in the SendPings() extension

Receiving
Handles trackbacks automatically which is nice

[manual link] - not sure if it works
Ex Trackback URL: http://www.somesite.com/trackback.axd?id=f272eac7-e004-4863-acd1-d37e75a00c57
&title=Your Post Title&url=Your post url&excerpt=Your Post Excerpt&blog_name=Your Blogname
 
[Hash is the Post.Id, changes for each post]
To make it easy for other people to figure out your trackback url, you should include it somewhere in your theme by the comments section.


PingBacks

What it's for:
Does the same thing as a trackback, but uses a different protocol. Sends less information, just adds a link back to your site in their comment section.


Sending
Same as trackback, but only initiated if trackback fails


Receiving
Handled automatically by blogengine.


Ping

What it's for:
Notifies blog directories/services when you update or add a new post.

How it works in Blogengine:
In Blogengine this is handled automatically every time you update an existing post or insert a new post. The SendPings() extension manages this and there is no setting to enable or disable this.

You can add/edit/delete the list of services ping, in the Admin->PingServices tab
 
Coordinator
Feb 9, 2009 at 10:25 PM
Ken, great summary!

In the web.config file for 1.4.5 and the latest changeset, there are HttpHandler entries for both trackback.axd and pingback.axd.  So, I'd expect both trackback and pingback receiving to work.

Pings, implemented in the SendPings extension should be disable-able on the Extensions tab in the control panel ... just like other extensions can be disabled.
Feb 9, 2009 at 11:02 PM
Edited Feb 9, 2009 at 11:29 PM

Hi Ben, I have the trackback.axd and pingback.axd in my web.config as well. In my Post.aspx file there is this xml data

  <asp:placeholder runat="server" id="phRDF">
    <!--
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
      <rdf:Description rdf:about="<%=Post.AbsoluteLink %>" dc:identifier="<%=Post.AbsoluteLink %>" dc:title="<%=Post.Title %>" trackback:ping="<%=Post.TrackbackLink %>" />
    </rdf:RDF>
    -->
  </asp:placeholder>


which exposes the trackback url in the html source, but there is none for the pingback.axd. I'm guessing blogengine prefers to send trackbacks over pingbacks and only if it the trackback fails will it send a pingback. I'm not sure how it exposes the pingback address when trackbacks are disabled and pingbacks are enabled.

I didn't see the enable/disable option for ping notifications, unless it is under a different label.

[Not sure if this was updated, this is from release 1.4.5.13]

 /// <summary>
  /// Executes the pings from the new thread.
  /// </summary>
  private static void Ping(IPublishable item, Uri itemUrl)
  {
        try
        {
            System.Threading.Thread.Sleep(2000);

            // Ping the specified ping services.
            BlogEngine.Core.Ping.PingService.Send(itemUrl);

            // Send trackbacks and pingbacks.
            if (!BlogSettings.Instance.EnableTrackBackSend && !BlogSettings.Instance.EnablePingBackSend)
                return;

            if (item.Content.ToUpperInvariant().Contains("\"HTTP"))
                BlogEngine.Core.Ping.Manager.Send(item, itemUrl);
        }
        catch (Exception)
        {
          // We need to catch this exception so the application doesn't get killed.
        }
  }
Coordinator
Feb 9, 2009 at 11:22 PM
If you look in post.aspx.cs, you'll see the following line:

if (BlogSettings.Instance.EnablePingBackReceive)
    Response.AppendHeader("x-pingback", "http://" + Request.Url.Authority + Utils.RelativeWebRoot + "pingback.axd");

So, the pingback url is added as a header in the response back to the browser.

For SendPings, the way all these extensions work is if you diable them on the Extensions tab in the control panel, then BlogEngine doesn't load the extension in memory ... resulting in the extension's code never running.  The extensions are loaded in the global.asax file in the root of your blog.  The code in there loads each extension into memory if it is marked as enabled.
Feb 9, 2009 at 11:38 PM
For some reason my posts do not have pingback.axd appended to the header even though it is enabled. I'll have to look into that one. I get what your saying with the SendPings() extension, you can just disable the whole extension and it won't run, but I was talking about an option in the admin panel that could be enabled or disabled for ping services, just like the trackback, and pingback options. Nothing fancy, just a simple checkbox that says enable/disable pingservices under the pingservices tab. It might not be the most useful setting, but it helps differentiate between the trackback and pingback settings, so you know what controls what,
Coordinator
Feb 9, 2009 at 11:48 PM
But there's a key difference between Trackbacks/Pingbacks and Pings.  Trackbacks/Pingbacks are built into BlogEngine which is why the capability to turn them on/off is on the Settings tab.  Pings, however, is not built into BE ... it is an extension.  All extensions are controlled on the Extensions tab in the control panel.  The list of extensions on the extensions tab is dynamic in that their existence is detected by being under App_Code/Extensions.  All the options on the Settings tab are fixed ... they're not dynamically loaded.

One thing to check on for the pingback header is that in addition to having the Receive Pingbacks box checked on the Settings tab, you have to pull up an actual post with the 36 character Guid in the Url.  I just noticed that.  Trackbacks works the same way where that phRDF placeholder control is only outputted when the post's Guid is in the url.  I just checked and do see the x-pingback response header for my 1.4.5 blog.
Coordinator
Feb 9, 2009 at 11:56 PM
Also, just wanted to mention that the x-pingback header is a response header like content-type, content-encoding and content-length, etc. is.  It's not added to the <head> section of the html page.  You can view the headers with tools like Fiddler or Firebug.
Feb 10, 2009 at 12:40 AM
Edited Feb 10, 2009 at 12:50 AM
Lol, no wonder I couldn't see it. Thanks Ben! Do you know how someone could invoke a pingback if trackbacks were disabled? Which url to use and the parameters?
Coordinator
Feb 10, 2009 at 12:56 AM
Sorry, I don't really know anything about pingbacks or trackbacks ... except what I've just discovered in this thread!  I imagine they would first get the pingback address (x-pingback).  Then they would send the pingback to that address sending whatever data is required by the pingback "standard".
Feb 10, 2009 at 12:57 AM
Edited Feb 10, 2009 at 1:05 AM
"Sorry, I don't really know anything about pingbacks or trackbacks ... " - no worries! I'll get to the bottom of this :)

Hmmm. I was taking a look at the trackback.axd file handler and noticed something is not adding

[Post.aspx]
    <!--
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
      <rdf:Description rdf:about="<%=Post.AbsoluteLink %>" dc:identifier="<%=Post.AbsoluteLink %>" dc:title="<%=Post.Title %>" trackback:ping="<%=Post.TrackbackLink %>" />
    </rdf:RDF>

[trackback.axd handler]

    public void ProcessRequest(HttpContext context)
        {
    string postId = context.Request.Params["id"]; ;
    string title = context.Request.Params["title"];
    string excerpt = context.Request.Params["excerpt"];
    string blog_name = context.Request.Params["blog_name"];
    string url = string.Empty;

}

Does the rdf comments relate to the parameters in the trackback.axd, because I can't find anywhere else where they are specified.
Coordinator
Feb 10, 2009 at 1:58 AM
Not sure what you mean exactly by "rdf comments".  If I were taking a guess, I'd imagine there's not necessarily a 1 to 1 connection between the RDF info and the data passed into the trackback.axd handler.

The RDF data in the post has the (1) post url, (2) post title, and the (3) trackback url.  When someone blogs about your blog post on his blog, his blog application will go to the post url the blogger put in his blog post.  His blog application will get those 3 pieces of RDF data out of your post.  The blog application then sends a request to the trackback url it got out of your post.  The information it sends in the request to your trackback url are those request params you cited ... postId (your post id), title (the title of his blog post), excerpt (an excerpt from his post where he talks about your post), blog name (his blog name), url (the url of his blog post).

At least this is how I would envision it working ...
Feb 10, 2009 at 3:17 AM
That makes sense... The rdf thing threw me through a loop and I'm still in it. I understand the trackback:ping tag, that is just so blog platforms can see if the post supports trackbacks. I'm also guessing that dc:identifier="<%=Post.AbsoluteLink %> is so the platform knows which url to send the trackback message to in case if it differs from the post url?. I have no idea what the rdf:about tag is for, or why the post.title is present. Other platforms just need to know that trackbacks are supported and the trackback link, and then they send their message.




Coordinator
Feb 10, 2009 at 3:26 AM
You can just navigate to one of your posts and do a View Source.  For easier viewing purposes, I extracted the 4 values in the rdf tag in a test post I created.

rdf:about="http://localhost/be24796/post/2009/02/10/post-5.aspx"
dc:identifier="http://localhost/be24796/post/2009/02/10/post-5.aspx"
dc:title="post 5"
trackback:ping="http://localhost/be24796/trackback.axd?id=8f5e5610-c387-4fa0-b020-db5b4fbdbb7b"

So, rdf:about and dc:identifier are the same.  The remote blog application will put one of these in the postId parameter it passes to trackback.axd.  Trackback.axd looks at the postId parameter to know which one of your posts the remote person is writing about.
Feb 10, 2009 at 3:40 AM
Edited Feb 10, 2009 at 3:43 AM
In the trackback.axd handler the following querystring parameters are pretty much required, otherwise the trackback will not be received by BlogEngine

string postId = context.Request.Params["id"]; ;
string title = context.Request.Params["title"];
string excerpt = context.Request.Params["excerpt"];   // This one is just confusing in the source code, but not required
string blog_name = context.Request.Params["blog_name"];
string url = string.Empty;


Is this a standard? If I was using Wordpress, or TypedPad how would I know to send those parameters? The rdf comment can give you 4 out of the 5, but you need to do a bit of work for some of them. I still don't get why the rdf:about and dc:identifier contain the same values, but that's not important. This stuff is very confusing :)
Feb 10, 2009 at 3:52 AM
It just seems like there is too much going on behind the scenes with trackbacks and pingbacks. The concept isn't exactly easy to comprehend for beginners, and when you factor in all the different blog platforms, some of which do things differently it's amazing any of these things work. Oh, and factor in the fact that there is no documentation on these features or how to use them, so your already handicapped from the start. We'll at least I know how to send them, I just have to cross my fingers that some other newb with a blog is well versed in these concepts and can figure out what to do if they would like to initate them on my blog.
Coordinator
Feb 10, 2009 at 4:09 AM
Actually, only 1 of the RDF values is passed back into trackback.axd -- postId.  The other 4 parameters are values related to the remote blog's post.  For example, with these RDF values:

rdf:about="http://localhost/be24796/post/2009/02/10/post-5.aspx"
dc:identifier="http://localhost/be24796/post/2009/02/10/post-5.aspx"
dc:title="post 5"
trackback:ping="http://localhost/be24796/trackback.axd?id=8f5e5610-c387-4fa0-b020-db5b4fbdbb7b"

A remote blogger, Bob, decides to blog about the "post 5" post on my blog.  He creates a blog on his site with these specs:

blog title: Did you hear about post 5?
blog name: Crazy Bob
blog url: www.crazybob.com/blog/did-you-hear-about-post-5
blog content: I just read this guys post 5 blog today (link to post-5 blog) ...

When Bob saves his blog post, his blogging application extracts the "link to post-5 blog" from his post, goes to that url and gets the RDF data.  From that, the remote blogger's application knows the trackback.axd link.  It then sends values similar to the following to my blog's trackback.axd:

postId = 8f5e5610-c387-4fa0-b020-db5b4fbdbb7b
title = Did you hear about post 5?
excerpt = I just read this guys post 5 blog today
blog_name = Crazy Bob
url = www.crazybob.com/blog/did-you-hear-about-post-5

BE gets these values in trackback.axd and adds a comment to my blog post (identified by the postId), using the information passed into trackback.axd.

The concept may take a little getting used to, but hopefully Discussions like this one you started will help.  I would imagine that the values passed into trackback.axd are defined in some standard and all blogging platforms have a set of trackback rules they adhere to.
Feb 10, 2009 at 4:25 AM
Great example Ben!

" It then sends values similar to the following to my blog's trackback.axd:"

This part was confusing me... From reviewing the code I know that Blogengine creates a TrackBackMessage object with those parameters that it sends, but the rdf comment was throwing me off big time with those extra fields that do nothing in my opinion. I also wasn't quite sure how other platforms handled such requests, if this was a standard used by all platforms or just one that BE uses. Thanks Ben, it makes perfect sense, it was all those "what if's" that were hard to factor in.