Planet Claire

some say she's from Mars

Installing BlogEngine.NET into a sub directory of umbraco

by Claire 7/14/2010 8:37:00 AM

I've just spent the last several hours working out how to do this so will now blog it in the hope that it will save myself & anyone else out there some time, as there doesn't seem to be too much out there on this subject yet.  References yes, but nothing that told me exactly how to do this, so that's what I'm putting down here.

Motivation

I love Umbraco, it's brilliant.  And I want to use the packages available when I can.  The Blog4Umbraco package is fine for simple needs but for a more demanding client I have found that it's been a bit wanting in the following areas:

  1. Moderation of comments before the event.  For me this is essential even on a simple blog that allows comments, due to the massive volume of comment spam on the net now.  I think it's fair to say that comment spam has probably surpassed email spam in nuisance value, at least for anyone who runs a blog.  Even this tiny little blog, which runs on an earlier version of BlogEngine.NET suffers, I need to find the time to upgrade so I can use the promising new anti spam features of the latest BlogEngine.NET!  Time, my worst enemy!! 
  2. Categories.  Blog4Umbraco only has tags.  We want categories, each with their own rss feed so we can have one for a newsletter (which can be consumed by mailchimp for example), one for updates to our site, one for news from members, etc etc.  Each of these rss feeds can then be consumed in different ways & in different places.  Cool bananas!
  3. Importing of old posts & backdating of posts.  The fact that this is not do-able in Blog4Umbraco is a real pain in the bum.

I know that Blog4Umbraco is open source & that there is work being done to address these issues, I've looked into it myself and hope to contribute more at some point but unfortunately I just don't have the time at the moment and the client's needs come first.  I have plenty of experience with using BlogEngine.NET so I decided to have a go at using it inside an umbraco site so that we could have all the features of a blog together with Umbraco's wonderful CMS features.

Goals

These are my goals, they may not be the same as yours.

  1. The latest versions of Umbraco(4.5) & BlogEngine.NET (1.6.1), on IIS7, .NET 4.0 in integrated mode, using the default xml for the blog data.  This is what I've tested in, but I'm hoping it will work for slightly earlier versions of Umbraco too.
  2. Keep my source in source control.  For my umbraco projects, after setting up the website & installing the database, I always start a web application project in Visual Studio & copy the relevant directories from the umbraco website into it, adding Post Build events to copy my changes back into the website.  I believe this is common practice for many umbraco developers & enables me to keep my templates, css, xslt, user controls & other addons in source control.  If I'm going to run BlogEngine.NET then I want to take the same approach - the files that I'm going to be changing go into the webapp project & get copied over on build.
  3. The blog will live in a sub directory (say "/blog"!), and NOT be an application of it's own in IIS.  This is because I want to use umbraco macros in my BlogEngine master page.  In this way I can easily have common navigation for both the main site & the blog, and share css files too.  The fact that it won't be it's own application makes it slightly more complicated.
  4. Minimal changes to the BlogEngine source and minimal disruptions to the Umbraco base, we don't want to have nightmares when it comes to upgrade time.

Get it done

  1. Install your umbraco site & get it up & running.  Make a visual studio web application project for it & add some post build events to copy over the relevant directories to the website. So now you've got 2 locations - the website which IIS is serving, and your project directory which should be kept in source control.

  2. Make a new folder in the website, say /blog, and copy the contents of the BlogEngine.NET website into it.
  3. Move the 3 asp.net folders, App_Code, App_Data, App_GlobalResources to the root folder, merging with existing.
  4. Move the dlls from the blog/bin directory to the root bin directory.
  5. Move web.sitemap to the root directory
  6. Move global.asax to the root directory, open it up in a text editor & remove the Application_Error method.  This doesn't work well in IIS7 integrated mode.  I like to use Elmah for error logging in my apps anyway.
  7. Delete App_global.asax.dll from the root bin directory.  This is from umbraco but apparently isn't really necessary & is safe to remove.  It will interfere with the global.asax from blogengine, which is needed.
  8. copy /blog/web.config into the project directory & include in the visual studio project.
  9. copy /blog/themes/Standard/*.* into the project directory & include in the visual studio project.  You can rename this theme to your own at this point. 
  10. copy /App_GlobalResources into the project directory & include in the visual studio project.
  11. Add post build events to copy the files added in 8, 9 & 10 to the website directory on build.  Include the bin directory in your post build events if not already.
  12. Open up the root web.config in visual studio & cut the following web.config sections from the blog folder, paste them into the root web.config
    1. configSections/sectionGroup name="BlogEngine"
    2. BlogEngine
    3. connectionStrings if needed (not needed for XML, can delete)
    4. appSettings
    5. system.web/compilation/assemblies (if not already there)
    6. system.web/machineKey
    7. system.web/authentication (overwrite the umbraco forms element)
    8. the xml providers from membership, roles and all the sitemap providers.
  13. Delete httpModules & httpHandlers sections from both web.configs, they are not needed on IIS7 and deleting them will enable us to get more useful error messages from IIS
  14. Delete the system.webServer/validation section & change validateIntegratedModeConfiguration="true" in the root web.config.  This will give us better error messages.
  15. Change the BlogEngine.VirtualPath AppSetting to "~/blog/", or whatever directory name you're using.
  16. Add "~/blog" to the umbracoReservedUrls AppSetting.
  17. At this point the project will not build for a couple of reasons:
    1. The theme files need to be converted to the web application format.  Right click on the blog folder in VS & "Convert to Web Application".
    2. Add a reference to the BlogEngine.Core.dll that's in the website's root bin.
  18. The project should now build & you should confirm that the files were copied to the website directory
  19. There are some paths in the website project that don't use the BlogEngine.VirtualPath setting.  I changed them directly in the website folder, rather than importing them into the project and having to convert them to web application format.  This is just because I don't need to keep them in source control for any other reason & I'm trying to keep it simple.  They are:
    1. 34 occurrences of ~/admin/ in the blog/admin directory, in web.sitemap and in /widgets/Administration/widget.ascx.  Replace to ~/blog/admin.  (An easy way to do this is to open up a copy of the whole blogengine solution in visual studio & do a global replace, then copy the files back to your website folder)
  20. Check that everything works on the root site & on your blog.

One gotcha you might find along the way

After you add the blogengine httpModule called you might get an "unsupported form of compression" error.  Fix this by manually editing the App_Data/settings.xml file & switching off HttpCompression: - <enablehttpcompression>False</enablehttpcompression>.  Touch the web.config to restart the website.  (You can also switch this off via the blogengine admin panel but it's possible you might not have got as far as logging in yet).

Still to resolve

Sharing membership & role providers.  To login to blogengine you'll need to set the default providers in web.config to the xml providers, but to login to umbraco you'll need the original umbraco providers.  I haven't solved this problem yet but don't expect it to be a show stopper.  I'll update here when I have more.

Summary

At this point you should be up & going with your umbraco site still working in the root, & blogengine up & running in the blog folder.  Umbraco macros should work in the site.master for your blog theme, and you should be able to set your blog site.master to share the same css as your main site, so making the 2 sites look the same.

This is early days for me but I'm optimistic I can make it work.

References

http://www.danielbardi.com/blog/post/2009/10/07/Setting-up-BlogEngineNet-with-Umbraco-CMS.aspx
Various posts on the blogengine forum including http://blogengine.codeplex.com/Thread/View.aspx?ThreadId=51114

Tags: ,

BlogEngine.NET | Umbraco