Category: Development

Running multiple websites under N2 CMS

RTFM indeed!

Don’t get me wrong, I really like N2 CMS, but the documentation blows chunks. The number of typos and spelling mistakes in both the online documentation and in the source-code comments is high, but some of the advice given is just plain wrong or out-of-date (which is almost worse than no documentation.. unless you are desperate for ideas). Time for somebody to write a book on N2 CMS… any takers?

The path to enlightenment has many turns

Basically don’t rely on one source of infomation for N2 CMS, use anything/everything you can find. Believe nothing, but try everything! For instance, when attempting to setup multiple website under a single N2 installation I read the single Advanced topic on the N2 site, followed by at least a dozen forum posts:

  • The Advanced topic page incorrectly says to change a “hosts” setting in the web.config, but it is called “host”. Little details like trip up newbie coders all the time.
  • The responses to some posts don’t actually seem to be answering the question asked. Some actually give code examples that are just plain wrong or at least misleading.
  • Multiple N2 websites does require correct setting up of IIS to have multiple domains/subdomains all pointing at the same IIS application.
  • Multiple N2 websites do not work under the Visual Studio debugging webserver. Any domains, aside from the default, are ignored.

How we got it working

  1. Added ISitesSource interface to our HomePage class(es). HomePage is our N2 content class (derived from ContentItem) and used for all our site home pages. You may have different ones per site instead.
  2. Implement a property called Host with an [EditableTextBox] property on any/all home page classes.
  3. Implement a GetSites method that yields an N2.Web.Site(Parent.ID, ID, Host) value on any home page classes. The Host value comes from the previous property we added in step 2. The ID is from the current node and the Parent.ID is the id of the root node that owns the start pages.
  4. Install a local copy of IIS for testing. This is needed as the Visual Studio debug website engine does not support host names (which is required for this feature to work). It means you will have the extra step of publishing your website under IIS to test multi-site functionality. To test one site at a time in Dev Studio just change the initial startPageId in the host setting in web.config.
  5. Add aliases to the hosts file to point any/all test domains at localhost (
  6. Publish and install your N2 CMS web site under IIS for your main site, e.g. under a domain called
  7. Ensure that site is running and you can get to the admin interface via /edit
  8. Add additional test sites e.g., but point the physical path of each site at the previous installation directory of the website. This ensures they all run the same web application, saving memory and sharing code/data.
  9. Run up the admin install, e.g. on
  10. Do a normal install, but make sure you add separate root and start nodes for your new site. This is critical as the root must be above all the new sites and each site will have its own start node.
  11. From within the admin interface add extra start nodes to the root node (one for each website you want) and set the Host property of each to its matching domain name (e.g.,
  12. Also put some differing values in the content property of each start node (so you can tell the different sites are working).
  13. Note the ID numbers of each start page, as these have to be listed in the web.config.
  14. Edit the host > sites settings in web.config, adding an entry per hostname/domain. These entries specify which hostnames point to which start nodes when they start.
  15. Now try your various domain/subdomain names under IE (chrome appears to ignore hosts file entries!). If it is working you will see your different start pages under each website.
  16. Give a sigh of relief.

I will pad this out with screen shots and code examples when I get a chance, but thought I should get down the details before I forget :)

Cheers, Dave

Adding a Newsfeed to N2 CMS – Part 2 The XML Feed

Feed me!

A “News feed” is a cool-sounding term that basically means a text file (in a specific format of course). “Text file” does not sound anywhere near so cool.

Where does my feed come from?

That depends… If you have licenced a commercial new feed, like Adfero, you would have been given a URL pointing to your own personal download.

There are various free feeds available too, in varying formats, but I am focusing on the Adfero format for this example.

Adfero format

The Adfero file is an hiearchical XML file. It simply contains multiple Articles, each with multiple Categories and multiple Photos per article.

To process this structure my simplest solution was to create equivalent classes for each major element in the feed file and parse the file hierarchically:

  • FeedArticle
  • FeedCategory
  • FeedPicture*
    • FeedImage

*Note: a FeedPicture represents the picture, a FeedImage represents that picture in a specific size. This way you can process large and thumbnail image details from the feed file the same way.

Each class has enough members to store the incoming XML data and some simple helper getters to return useful items (like caption of 1st image, if any images are present). The classes and members are:


  • NewsArticleId (int) – News article id (primary key in database)
  • ArticleNumber (string) – Unique article number from feed
  • Heading (string) – Article heading
  • Created (DateTime) – Date/Time article was created
  • Date (DateTime) – Publication date of article
  • Contents (string) – Contents/body or article
  • Summary (string) – Summary of article
  • Caption (string) – Shortcut: get caption of 1st image
  • PictureList (List<FeedPicture>) – List of 1 or more images, each with thumbnail and large
  • CategoryList (List<FeedCategory>) – List of categories for this article
  • LargeImageUrl (string) – Shortcut: get URL of 1st large image
  • LargeImageWidth (int) – Shortcut: get width of 1st large image
  • LargeImageHeight (int) – Shortcut: get height of 1st large image
  • SmallImageUrl (string) – Shortcut: get URL of 1st thumbnail image
  • SmallImageWidth (int) – Shortcut: get width of 1st thumbnail image
  • SmallImageHeight (int) – Shortcut: get height of 1st thumbnail image


  • Found (bool) – For internal processing use – was this category found in the database (and for the current article)?
  • CategoryId (int) – Unique category id – database PK
  • CategoryNumber (string) – Unique category number (from feed)
  • CategoryName (string) – Display name of category


  • Portrait (bool) – is the image narrower than tall?
  • AspectRatio (float) – Aspect ratio of width to height of large image
  • PhotoId (int) – Original photo id (from feed)
  • LargeImage (FeedImage) – The large image details (if any)
  • SmallImage (FeedImage) – The small image details (if any)
  • Caption (string) – A text caption for the images


  • ImageURL (string) – Image URL
  • ImageSize (Size) – Size of image
  • Width (int) – Width of image – helper
  • Height (int) – Height of image – helper
  • AspectRatio (float) – Ratio of width to height

Downloading the News feed

The .Net WebClient class is wonderful for downloading content asynchronously. Give it the URL and a local target filename and it does the download for you. If you attach an event hander to the DownloadFileCompleted event, you get informed when the file has been download. This means you now have an XML file on the server, ready to process like any other local file.

Eating the feed

The basic principal of parsing this XML feed follows the hierarchical structure of the feed.

  • Create an XmlTextReader
    • While there are more article nodes
    • Add each processed article to a list of all articles
    • Store the articles in the list

The article processing consists of checking child nodes and either storing attibutes (like Heading, Contents etc), or processing a group of child pictures or child categories. The resulting FeedArticle object is returned:

  • Create a blank FeedArticle
    • While we are processing nodes of the current article
      • if node name is “Heading”, store the value as the article heading
      • if node name is “Date”, store the value as the article date
      • if node name is “Contents”, store the value as the article contents
      • if node name is “Summary”, store the value as the article summary
      • if node name is “Pictures”, process any pictures for this article
      • if node name is “Categories”, process any categories for this article

The picture processing is similar and consists of checking child nodes and either storing attibutes (like PhotoTag etc), or processing a group of child images. The resulting FeedPicture objects are added to the FeedArticle:

  • Create a blank FeedPicture
    • While we are processing picture nodes
      • if node name is “Large”, process an image and store in the large FeedImage
      • if node name is “Small”, process an image and store in the small FeedImage
      • if node name is “PhotoTag”, store the value as the picture caption

The image processing is even simpler and consists only of checking child nodes and storing attibutes (like Width, Height and URL etc) so I will not bother with pseudo-code.

The categories processing consists of processing a group of child category nodes. The resulting FeedCategory objects are added to the FeedArticle.

The category processing (1 category) consists only of checking child nodes and storing attibutes (like ID and the text of the category name) so I will not bother with pseudo-code.

Storing the results

After running these parsing steps you wind up with a hierarchy of objects that you can iterate to run any processing you like. Typically for feed processing you will look for existing entries and see if they are new or changed. If nothing else this allow you to spit out statistics on how many new articles were added or changed from a given day’s feed.

Enough for now, in Part 3 we will look at the merging of the simple article tables, now updated by the previous steps, into the N2 CMS structure. That’s where the fun really begins…

Cheers, Dave

Adding a Newsfeed to N2 CMS – Part 1

Time for something a little more practical…

Adding a 3rd party newsfeed to a CMS is something that many may eventually want to do. Newsfeeds with daily-fresh content can add a lot of SEO value to a website. This basically involves downloading a formatted XML file (e.g. from a company like Adfero) and merging the articles into your CMS, so that they display in your lovely news archives and on your front page (and wherever else you want to see them).

This is the second time I have worked with adding Adfero news feeds to a system, so you can learn from my mistakes without having to make them yourself.

The previous project included a pass-through system, where links were dynamically inserted into the Adfero copy on-the-fly. The links were matched to keywords and phrases. A new URL was provided to clients to pickup the modified newsfeed, now containing hyperlinks embedded into the original articles.

The current project is a bit more straight forward, merging a newsfeed into a CMS system, but built on my knowledge of the previous project.

The secret to merging News feeds into a CMS is  “DO NOT merge the feed directly into the CMS database”. Honestly, there are so many things that can change (possibly even your entire CMS) that you want to keep this process separated into discrete reproducible/testable steps.

Stage 1 processing:

  • Run 1-4 times a day, depending on how lively your newsfeed is.
  • Download the Newsfeed file to a local file.
  • Also allow for specific local file processing as well (so you can restore from XML news archive files)
  • Extract a hierarchy of articles, categories and photos
  • Add new articles, categories and photos to the News tables
  • Update changed articles, categories and photos in the News tables
  • Ignore any completely unchanged articles

The end result of all this is a local database (usually 3 tables) of all past and current articles. Ready for you to do with what you wish!

Stage 2 processing (anytime after step 1):

  • Always run though the stored archive of all articles (does not take long, even for many 1000s).
  • Find the correct parent for the CMS item (there may be more than one… more about this in Part 2).
  • If an existing CMS item exists for an article, and has changed, update that CMS item.
  • If no existing CMS item exists for an article, create a new article.
  • If an existing CMS item exists for an article, and has not changed, do nothing.
  • If the CMS item is under the wrong parent (e.g. it has been deleted) move it back.


The 3 separate groups of data you will work with are

  • The XML Feed file
  • The local news database tables
  • The CMS database

Best to take this system one chunk at a time. In part 2 we will look at the XML feed format and describe how you can process it in a systematic way. The techniques used can be applied to many types of XML file.

Cheers, Dave

Silverlight at the end of the tunnel!

Don’t let the GUI get you down…

The problem with really complicated websites, is that the interface of a standard HTML based website really lets you down.

We are designing around a very powerful and very scaleable database design. In many ways it is like an Amazon-style database, but with it’s own unique twists.

The requirements for editing content on work well enough in our Site Manager, which is a full-blown Windows application with drag-drop, cut & paste etc, but trying to make the data entry usable on a website is a struggle with established technology. Even our favorite combination of ASP.NET with AJAX still feels sluggish and like we are trapped in the 90′s.

All about timing…

Just last month, Microsoft has released their Azure platform (Microsoft’s cloud computing option). This gives us the massive processing and storage potential we have been waiting for, without having to switch from our prefered C#/.Net combination to Python or another language.

Microsoft’s answer to flash, Silverlight, is now in a stable usuable state with the release of Silverlight 2. The power of Silverlight is in putting desktop-app functionality into a web-browser. The down-side is Silverlight’s current browser support (only about 4 main browsers can run it as of this writing).

What now?

Now we have the necessary “possibilities” covered, we are currently buried up to our necks in Silverlight reference materials and code samples to see how practical it is to turn our crazy ideas into reality.

We can’t find the exact third-party controls we need for, but we have seen enough of what is possible with Silverlight to know we can build our own… One component in particular that we are building for will have such broad appeal that we will likely offer it as a component for other developers. That one should appear publicly in the next few weeks.

Anyway, as I like to say, that website won’t write itself, so I must get back to cutting code.

Keep a lookup for new announcements from us over the Xmas period!

Barcode readable True Type font

The trouble with barcodes

We use barcode readers to track boxes of stock and have found a number of issues with the fonts available.

Generally they are either too expensive, unreliable (when printed) or don’t support lowercase letters (on the human readable lower part). We also hate seeing the “asterisk” markers required at each end.

In the true style of geeks when it doubt, reinvent the wheel:

After a little investigation, we created our own Code 39 Bar code font that meets our specific requirements.

We quite like the FontStruct website. Give do give it, and our font, a try and leave feedback.


Free Krypton Toolkit!

A complete set of Free .Net user controls

If you work with .Net and want to develop professional and “really cool looking” user interfaces, give the Krypton Toolkit a try.

We now use it as standard in all our .Net Windows applications to give that extra touch of magic!

Free user controls for Windows Forms

The Krypton toolkit provides a huge set of controls that you can simply drag and drop into your own .Net Windows applications. Features include:

  • Free for commercial use
  • Source code available
  • Full documentation
  • Sample code included
  • Office 2007 palettes
  • Create your own color palettes

WordPress Themes