Tags: , | Categories: Blog Posted by al on 6/2/2010 10:05 PM | Comments (3)

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;
   5:  
   6: namespace Al
   7: {
   8:  
   9:     /// <summary>
  10:     /// Summary description for GraffitiModule
  11:     /// </summary>
  12:     public class GraffitiModule : IHttpModule
  13:     {
  14:         public GraffitiModule()
  15:         {
  16:             //
  17:             // TODO: Add constructor logic here
  18:             //
  19:         }
  20:  
  21:         #region IHttpModule Members
  22:  
  23:         public void Dispose()
  24:         {
  25:             //
  26:         }
  27:  
  28:         public void Init(HttpApplication context)
  29:         {
  30:             context.BeginRequest += new EventHandler(context_BeginRequest);
  31:         }
  32:  
  33:         void context_BeginRequest(object sender, EventArgs e)
  34:         {
  35:             HttpContext context = ((HttpApplication)sender).Context;
  36:  
  37:             if (context.Request.Url.OriginalString.ToLower().IndexOf("/blog/") > 0)
  38:             {
  39:                 string sOriginal = context.Request.Url.OriginalString.ToLower();
  40:  
  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";
  48:  
  49:                 context.Response.Redirect(sOriginal);
  50:             }
  51:         }
  52:  
  53:         #endregion
  54:     }
  55: }

 

   1: <httpModules>
   2:       <add name="GraffitiModule" type="Al.GraffitiModule"/>
   3:         

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.

Cheers

Al



blog comments powered by Disqus