TrackbackHandler Update

Oct 25, 2008 at 4:49 PM
I know this has been discussed to death here, but this isn't a complaint. It's more of a suggestion. I noticed that with WordPress blog sites, if for some strange reason a person put the trackback URL in the browser address bar and followed it, it would redirect them back to the correct post. I tried this same thing in my blog and I'm redirected to the blog root. Wondering why this happened, I looked at the TrackbackHandler.cs file and noticed it attempts to do the same as the WordPress implementation. The problem is on line 61. It checks the postId to see if it's null or empty and if it's 36 characters long. Only ater those requirements are filled, with others, is it allowed to look for the post in question. Well, if the check fails, it check to see if the post is null, which it alway is if it gets to this point, so it never redirects to the post. Here's how it looks currently:

            Post post = null;
            if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(postId) && !string.IsNullOrEmpty(blog_name) && postId.Length == 36)
            {
                post = Post.GetPost(new Guid(postId));
                ...
            }
            else if (post != null)
            {                
                context.Response.Redirect(post.RelativeLink.ToString());
            }
            else
            {
                context.Response.Redirect(Utils.RelativeWebRoot);
            }

If we did this:
            Post post = null;
            if(!string.IsNullOrEmpty(postId) && postId.Length==36)
                post = Post.GetPost(new Guid(postId));
            if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(blog_name) && post != null)

then the rest of the code works like it's supposed to.