Thursday, 30 September 2010

BlogEngine.NET logoI use BlogEngine.NET to run my blog. I like it because it is a fully featured blogging platform that is free, open source and ASP.NET based. However, it isn't perfect, and if you want to run it in a subdirectory of a website, without making that subdirectory it's own application, there are a few tweaks needed to get it up and running. Having BlogEngine.NET in a subdirectory has several advantages; it can share Masterpages and usercontrols with the rest of the site and is easier to integrate with an existing website. So here are the steps required.

First of all pop over to the BlogEngine.NET website and download the lastest version of the code, which at the time of writing this article is currently 1.6.1.

Folder Structure

Once you have the files downloaded, they need to be moved about. Create a /blog directory and move the files until the folder structure looks like the screenshot below. Notice that WidgetEditor.aspx and widget.js have been moved to an admin folder under /blog and that there is a new blank file, Add_entry.aspx, which you will need to create, in the /blog/admin/pages folder. Also, the App_GlobalResources folder has been copied to the /blog folder.

BlogEngine.NET files

Code Changes

Now that you have moved the files around BlogEngine.NET will error if you try to run it. So, there are several changes that need to be made to the code, ranging from adding in new controls to changing the way file paths are handled.

Web.config - The first change is to the web.config file. Simply change the application path to ~/blog/ as shown below:

BlogEngine.NET files

Admin - Two files in the admin directory need changing. Find the function AdminPhoto() in the code behind file admin1.master.cs and change it as shown below:

BlogEngine.NET files

Also, the usercontrol tinyMCE.ascx needs a change to the path to a Javascript file:

BlogEngine.NET files

In the folder App_Code/Controls find the file Blogroll.cs and locate the line HtmlImage image = new HtmlImage();. Change the code as below, which adds an ASP.NET image control so the path to the image is correct.

BlogEngine.NET files

Now we have those files set up, it's time to turn to the /blog directory and edit some files in there.

archive.aspx.cs - The path to the RSS button graphic needs to be changed in this file:

BlogEngine.NET files

default.aspx - A simple file path change:

BlogEngine.NET files

post.aspx - Again, a simple file path change:

BlogEngine.NET files

site.master - BlogEngine.NET comes with several built in themes and there are many more to download. The default theme's master page, in /blog/themes/Standard, needs this change, again to get the correct image path.

BlogEngine.NET files

BlogRoll - Several widgets also need updating. First off is /blog/widgets/BlogRoll/widget.ascx:

BlogEngine.NET files

Tag Cloud - The path also needs changing in /blog/widgets/Tag cloud/edit.ascx:

BlogEngine.NET files

Twitter - The file /blog/widgets/Twitter/edit.ascx need an update:

BlogEngine.NET files

Although the directory setting has been updated in web.config to tell BlogEngine.NET that it is in the /blog directory, the edit post page will redirect to the wrong directory. To fix this you could download the C# source code for the core functions and update it from there. There is an easier option. Simply create a file in /blog/admin/pages called Add_entry.aspx and add the following code:

BlogEngine.NET files

Set /blog/default.aspx as the start page in Visual Studio and you should now be able to run the website without any errors and with a fully functioning BlogEngine.NET installation in the /blog directory. There may well be other issues that I have not come across yet, but, as can been seen from the code above, most of them will probably involve incorrect file paths and should be relatively easy to fix.


blog comments powered by Disqus