From my old blog, March 10, 2008. No longer maintained.

Multiple blogs on the BlogEngine – an implementation

The original is on archive.org.

I had a pseudo  epiphany this day regarding BlogEngine.  I was able to create a multi-blog site with BlogEngine.  There are only a few things that you have to do.  This example supports ONLY supports domain + port, virtual directories, and subdomains + domain. 

  1. You need a fresh copy of BlogEngine from http://codeplex.com/blogengine.  I have two utility methods in the Utils.cs that is needed.
  2. Create a directory “~/setup/defaultinstall/” and copy all the default files that you want to include in the new BE.N instance in this directory.  I recommend just copying the default entries in the App_Data folder.  Make sure you set the files to read.
  3. Make the following changes to the BlogSettings.cs so the StorageLocation property matches Code Change 1.  Decide if you are going to use sub-domains, domains or virtual directories. 
  4. Start the application.  If you have IIS set with the appropriate header or have a virtual directory setup this example will auto copy all the files in the “~/setup/defaultinstall/” and create a new site. 

Don’t try this on a production site just yet.  This is my first successful run and it seems to be working.  I need some feedback.

Know what is weird?  I was looking for a subdomain getter method and found one written by Mads @ http://www.webpronews.com/expertarticles/2006/11/30/retrieve-subdomain-from-a-url-in-c.  Small, small, small world.  It was destiny so I included it in the Utils.cs.

Code Change 1:

public string StorageLocation
     {
         get
         {
             //for use with virtual subdomains + domain + ports

             // string folder = @"~/app_data/" + Utils.GetSubDomain(HttpContext.Current.Request.Url)  + HttpContext.Current.Request.Url.DnsSafeHost + HttpContext.Current.Request.Url.Port.ToString() + "/";

             //for use with virtual direcory

             string folder = @"~/app_data/" + HttpContext.Current.Request.Url.Segments[1].ToLowerInvariant() + "/";

             //for use with virtual domain and   subdomains

            // string folder = @"~/app_data/" + Utils.GetSubDomain(HttpContext.Current.Request.Url) + HttpContext.Current.Request.Url.DnsSafeHost + "/";

             string defaultDataFolder = HttpContext.Current.Server.MapPath("~/setup/DefaultInstall/");

             if (!Directory.Exists(HttpContext.Current.Server.MapPath(folder)))
             {

                 object _lock = new object();

                 lock (_lock)
                 {

                     Directory.CreateDirectory(HttpContext.Current.Server.MapPath(folder));

                     Utils.RecursiveDirectoryCopy(defaultDataFolder, HttpContext.Current.Server.MapPath(folder), true, false);

                 }
             }

             return folder;
         }

         set
         {
             if (String.IsNullOrEmpty(value))
             {
                 storageLocation = String.Empty;
             }
             else
             {
                 storageLocation = value;
             }
         }
     }

All old blog posts