Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

Redirecting to posts in BlogEngine

by Jim Feb 15, 2010 9:38 PM

Since I’ve moved my blog from Blogger to BlogEngine, the URLs have of course changed. The old posts were .html files, so my asp.net application doesn’t process them, the and resulting 404 error falls to Brinkster (my host) to handle.

I can configure my Brinkster account to load BlogEngine’s Error404.aspx page in these cases, and the following code will successfully redirect those requests to the new BlogEngine post.

Blogger and BlogEngine both follow the convention of naming a post with the title, replacing spaces with commas.

// Jim: check for brinkster 404 redirect query string
// The query string is not name=value, it's this:
// 404;http://www.jimandkatrin.com:80/CodeBlog/2009/12/some-thoughts-on-code-reviews.html

string reg = @"^404;http://www.jimandkatrin.com:80/CodeBlog/[0-9]{4}/[0-9]{2}/(.*)\.html$";
string qs = Server.UrlDecode(Request.QueryString.ToString()); // raw query string
if (!string.IsNullOrEmpty(qs) &&
  System.Text.RegularExpressions.Regex.IsMatch(qs, reg,
    System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
  // Get the match, and construct a new URL out of it, in the BlogEngine format:
  System.Text.RegularExpressions.Match match =
  System.Text.RegularExpressions.Regex.Match(qs, reg);
  string url = string.Format("~/post/{0}.aspx", match.Groups[1]);

  Response.Redirect(url);
  Response.End();
  return;
}

// Jim: Set response code so that redirects from Brinkster 404 will actually 
// return the response code 404
Response.StatusCode = 404;
Response.Status = "404 Not Found";

The status code at the end causes the page to actually return a 404 status code, rather than a 200 OK, when Brinkster redirects to this page.

Switch to BlogEngine.NET

by Jim Feb 13, 2010 7:53 PM

I’ve always wanted to host my own blogging software, rather than relying on Blogger, and their impending deprecation of FTP publishing got me moving on that.

After some research into various .NET blog software, I settled on BlogEngine.NET, to be hosted in my Brinkster account. I thought I would write a few notes on the transition.

The first thing to do was ensure that I could run a separate web application under the root – I have a “Pro” account with Brinkster, and setting up a new application at /codeblog/ took less than five minutes, through their online support.

Next was to download the BlogEngine source code (currently 1.6.0.0,) and open it in Visual Studio 2008; this went without a hitch. If you add it to source control, you’ll need to be sure that the files under App_Data remain writeable (I’m using the default XML file storage option.)

The next task was importing all my old posts into BlogEngine. I used Aaron Lerch's powershell script to convert from Blogger to the BlogML format. Follow the directions in the comments to get the script working, if this is your fist time messing with powershell; note that you’ll have to run powershell as an administrator. If you have two blogs under your blogger profile, they will be output as separate top-level <blog> elements to the output file; open the file with notepad and move the individual <blog> elements to separate files.

BlogML can be imported directly into BlogEngine, but first I had to replace some special characters that the powershell script didn’t handle correctly:

[’] - &amp;rsquo;  (right single quote, or apostrophe)
[‘] - &amp;lsquo;  (left single quote)
[“] - &amp;ldquo;  (left double quote)
[–] - &amp;ndash;  (dash)
[…] - &amp;hellip; (ellipsis)
[†] - &amp;rdquo;  (right double quote)

Yes, there’s a character in that last group, you just can’t see it in any text editor I tried. You can, however, select and replace it from Visual Studio.

There were a couple of disappointments in this process: the tags were not imported from my BlogML files into BlogEngine (which is a bug,) and of my old links are broken, which I knew was going to happen. I can probably fix that with a little code, though.

All in all, a very easy transition. The default template was functional, and I spent a while working on the custom one you’re looking at now. The templates are easy to tweak and edit, and there are plenty available for download.