In my previous post I moved away from Graffiti CMS to find the perfect blog engine for me, in the journey I found BlogEngine.NET, perfect name for what I was looking for, yet I spent some time after the migration using BlogML to make sure all the urls still work, so all people that get into my blog from searching, almost all, still can find the correct post by the link. There is nothing worse than a broken link isn’t it? I made some modifications to BlogEngine.NET as a form as a extension, that is nothing else than a HttpModule.
Now Graffiti uses the category as a link and creates a directory per post if running under IIS6, I was wise when using Graffiti CMS to add all post blogs under blog, so all posts have the link of blog on the url, something that BlogEngine.NET is the post directory. So I had to make sure any request to blog will be handle by my httpmodule. Now if you are running your BlogEngine.NET under IIS6, you still need to create a directory called blog, otherwise your httpmodule won’t be called, if you are running under IIS7, you don’t have to worry about that one.
As I said before Graffiti CMS creates a directory per post blog, in BlogEngine.NET, every post is a aspx page, so modules can redirect them, that’s why my module rewrites the end of the title to .aspx.
Also a few spaces in Graffiti are converted to dashes (-) and in BlogEngine.NET some are removed, so I had to check a few URLS and removed those, instead of hard coding it as I did for the test, I am working in a XML file that I can add as many changes as I want.
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Web;
6: namespace Al
9: /// <summary>
10: /// Summary description for GraffitiModule
11: /// </summary>
12: public class GraffitiModule : IHttpModule
14: public GraffitiModule()
17: // TODO: Add constructor logic here
21: #region IHttpModule Members
23: public void Dispose()
28: public void Init(HttpApplication context)
30: context.BeginRequest += new EventHandler(context_BeginRequest);
33: void context_BeginRequest(object sender, EventArgs e)
35: HttpContext context = ((HttpApplication)sender).Context;
37: if (context.Request.Url.OriginalString.ToLower().IndexOf("/blog/") > 0)
39: string sOriginal = context.Request.Url.OriginalString.ToLower();
41: sOriginal = sOriginal.Replace("/blog/", "/post/");
42: sOriginal = sOriginal.Replace("default.aspx", "");
43: sOriginal = sOriginal.Replace("sql-server-compact-edition-3-5-in-visual", "sql-server-compact-edition-35-in-visual");
44: sOriginal = sOriginal.Replace("4-0", "40");
45: sOriginal = sOriginal.Replace("3-5", "35");
46: sOriginal = sOriginal.Substring(0, sOriginal.Length - 1);
47: sOriginal = sOriginal + ".aspx";
2: <add name="GraffitiModule" type="Al.GraffitiModule"/>
Hope that helps anybody moving to BlogEngine.NET can use this idea, when I got some time to finish my real Extension with a configuration, I’ll make sure to share it here.
I got a few emails this week of people asking me, why the change to BlogEngine.NET instead of SubText, well, the answer is simple, besides http://darkfalz.com/ told me, as well as the code was very easy for me to grab that application and write the changes I wanted to make, yet I personally love the mobile theme that BlogEngine.NET has for the iPhone.