[eng] BlogEngine multibloging made easy!

Published 22 September 08 10:23 AM

While I was on New Zealand last year, I wondered what I would take to make a BlogEnginge "multiblog" application. I spoke to Mads about the issue, hoping he had already been implementing that feature somewhere under the covers of BE, but unfortuneatly I came to early.

He told me that one of the developers on the famouse piece of software actually was working on such a feature, but only in his sparetime. So I contacted the developer for more details. His name is Roman D. Clarkson and has been working on BE for quite some time. Roman told me about his implementation and I went off, trying to run and test it, all while he was developing it. Hours, days and weeks went by. Eventually I realised that my issue was bigger than I had first expected, and all of a sudden I felt like one of those customers that order a feature but doesn't realize how much time it will take. Doooh!

The multiblog application came to my mind when I was preparing ActiveDeveloper.dk for handling more blogs. I felt crippled because I had to log on to the server, configure a virtual directory and move files each time a new blog had to be created. Booooring work!

I didn't want to change the blogging platform to something else, because I believe in supporting a local project, and because there is no blogging software that is as good as BlogEngine.

On Friday night I had been over at ZYB to drink a cold beer with Mads. The guys over there are seriously having fun!!! We didn't talk about the multiblog feature at all, because the application left my mind months ago. Instead we talked about who is going to TechEd EMEA and who we would like to meet down there.

I left ZYB early and went home to watch a movie. I accidently turned on my computer while sitting in my couch and thought "ohh well, I guess I could fire up Visual Studio and build something". So I did.

A couple of days ago I had fallen in love with the IIS 7 API, so the first thing I did was to include the Microsoft.Web.Administration.dll file in the new project. But I also have a lot of love for BlogEngine. All of the sudden I realised that my "multiblog" application could become true, or at least kind of :)

I added a IIS web site called MultiBlogs and applied my desired configuration to it.

IISsite

I configured the config directory under "%SystemDir%\Windows\System32\inetsrv\config" and had to add the IIS_USERS to the user list and give it sufficient rights.

applySecurity

If you want to read or write to the files withn the config folder, from a website, you need to add this group.

Then I downloaded the lateset version of BlogEngine and created a directory where I copied a all the BlogEngine files into. I named this directory "BlogFiles".

BlogFiles

So now I was ready to get "code cracker lacking". So I opened up the MultiBlogs website from Visual Studio.

I created a simple page where I added a few controls.

<form id="form1" runat="server">
<div>
    What is my name ?
    <asp:TextBox ID="tbBlogName" runat="server" />
    <asp:RequiredFieldValidator ID="rfvBlogName" ControlToValidate="tbBlogName" ErrorMessage="*"
        runat="server" />
    <asp:Button ID="Button1" Text="Fyyyyr" runat="server" OnClick="Unnamed1_Click" />
    <br />
    <asp:Label ID="lblMessage" runat="server" />
</div>
</form>

I added 2 simple classes in my App_Code directory. BlogInstaller.cs and IISHandler.cs.

I wanted to use the BlogInstaller class for creating the new blog directory on the disk, but also for the copying of files. The files that should be copied from the "BlogFiles" directory into the new directory. So 2 methods and a construtor - easy money!

IISHandler.cs, I would this for 2 things as well. Check if an application already exists in the "MultiBlogs" website, but it would also be the creator for both an application and a virtual directory for the new blog on the IIS.

The code file for the aspx page ended up looking like this.

private const string IISSiteDirectoryPath = @"C:\WebSites\MultiBlogs\";
private const string BlogCleanInstallDirectoryPath = @"C:\WebSites\BlogFiles\BlogEngine.Web\";
private const string ApplicationPoolName = "MultiBlogs";

protected void Unnamed1_Click( object sender, EventArgs e )
{
    if( Page.IsValid ) {
        string blogName = tbBlogName.Text;

        foreach( var item in VirtualDirectoryCollection.InvalidVirtualDirectoryPathCharacters() ) {
            if( blogName.Contains( item ) ) {
                lblMessage.Text = String.Concat( item, " is not allowed!" );
                return;
            }
        }

        if( !IISHandler.ApplicationExists( IISSiteDirectoryPath, blogName, ApplicationPoolName ) ) {
            BlogInstaller installer = new BlogInstaller( String.Concat( IISSiteDirectoryPath, blogName ), new DirectoryInfo( BlogCleanInstallDirectoryPath ), new DirectoryInfo( IISSiteDirectoryPath + blogName ) );
            IISHandler.CreateVirtualDirectory( IISSiteDirectoryPath, blogName, ApplicationPoolName );

            lblMessage.Text = "Created!";
        } else {
            lblMessage.Text = "Exists!";
        }
    }
}

Now, it is possible for me to create blogs on the fly. Now I only need a site where I can install it...dohhhh!

Download the sourcecode here.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# qthangit said on September 23, 2008 6:17 AM:

Can I configure MultiBlog (BlogEngine) on IIS 6?

I can't upgare from IIS 6 to IIS 7

# qthangit said on September 23, 2008 10:42 AM:

I want to have multi blog on single database. anybody can help me!

Thank you very very much!

# malvarez said on September 30, 2008 12:46 AM:

Please Daniel ...

I also am of the club of:

"Can I configure MultiBlog (BlogEngine) on IIS 6? "

"I can't upgare from IIS 6 to IIS 7"

do you know like doing it?

Thanks ...

# danielmf said on September 30, 2008 4:45 AM:

Guys, look at http://vadstup.dk for IIS 6 version :)

# Yanga said on October 1, 2008 1:54 PM:

The correct link for the IIS 6 version : http://www.vadstrup.dk

# qthangit said on October 2, 2008 12:53 AM:

I have deployed successful!

I still have a bit worry about this way! I like the way that the same database for multi blogs. I will wait for that way

Thank you very much

# BJ Knudson said on October 9, 2008 9:23 PM:

Hi,

For some reason this code copies the files, but crashes on this line;

application.ApplicationPoolName = serverManager.ApplicationPools[ applicationPoolName ].Name;

With a NullReferenceException.  It suggests to use the "new" keyword to create an instance of the object.  I'm not sure what I'm doing wrong.  

Visual Studio 2008

# Tommy Boy said on November 14, 2008 9:22 PM:

Great work man.  If these dudes can make multi-blogs centralized in the API without requiring this IIS workaround, it would be immense for our projects.

# Fraga said on January 14, 2009 4:09 PM:

I have problems, giving the right permision to the App_Data, with iis 6, I guess because there is no

C:\WINDOWS\system32\inetsrv\config folder.

# Brennan Stehling said on February 24, 2009 7:32 PM:

Interesting, but maybe this could be done more securely so you do not have to give the web site write access to your configuration. What I would do is run a .NET Windows Service that you web site can talk with over WCF. Then I would run that Windows Service as a user that is granted specific access to the IIS configuration. That way you do not have to open up access to the entire web site and you can have the Windows Service only talk on localhost so it is much more secure.

Still I would like a way to not replace all of those files. A little URL mapping and some changes to BE and you may have that solution as well.

You use of the Microsoft.Web.Administration.dll assembly is interesting. I will have to look into what I can do with that.

# Interview gal said on March 18, 2009 1:01 AM:

Good concept, though I couldn't make it work on IIS 6. Keep crashing with null reference exception.

# Interview gal said on March 18, 2009 1:01 AM:

Good concept, though I couldn't make it work on IIS 6. Keep crashing with null reference exception.

# Torrent Articles said on April 29, 2009 3:12 AM:

Just wanna say thank you for welcoming me in your website and also for the information that you have included in this website.

Hope that this will not be the last post that I could be read written by you webmaster! Thanks for this useful information. Have a nice day webmaster!

# Torrent Articles said on April 30, 2009 4:51 AM:

Just wanna say thank you for the information that you have been shared. You created a blog that really suits to my taste.

# IPO said on June 2, 2009 4:47 AM:

Thanks for the information that was helpful for me.

# Grant GRiffith said on August 28, 2009 4:40 PM:

Am trying to get the multiblog working and keep getting an error when it is asked to create a new one.  Does this still work on the newest version? 1.5

Here is the error I am getting... Maybe something simple I missed???

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 39: Site site = serverManager.Sites[ applicationPoolName ];

Line 40:

Line 41: var a = ( from v in site.Applications

Line 42:  where v.Path.Replace( "/", String.Empty ) == applicationName

Line 43:  select v ).DefaultIfEmpty();

Source File: f:\clients\yada.com\multiblogs\App_Code\IISHandler.cs    Line: 41

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

This Blog

Syndication

Page view tracker