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.
- You need a fresh copy of BlogEngine from http://codeplex.com/blogengine. I have two utility methods in the Utils.cs that is needed.
- 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.
- 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.
- 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.
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;
}
}
}
2b4c84a9-6815-42e6-a06b-a688c65e198f|5|5.0