Multiple sites

N2 supports using the same database and web application to serve differnt content depending on the visited domain. E.g we could have a content structure that looks like this:

  • Root
    • Main site: https://www.company.com
      • Company information
    • Subsite: https://importantproduct.company.com
      • Product information
    • Other site: https://www.subsidiarycompany.com
      • Other interesting stuff...

Some benefits of this approach compared to having multiple installations:

  • It might be more appealing to users - people who edit content on the site will see everything
  • The sites can run in the same virtual application consuming less memory and resources
  • The sites can share common content resources such as news product information or users
  • Ease of deployment - update all sites at one time

To experiment with multiple sites the current version of N2 (1.3.2) requires some configuration and implementation:

Having some hosts to experiment with

For production you would use your regular DNS service and point out either the same IP address (with host headers) or adding multilpe interfaces to the web server. To test locally you can modify your hosts file located at C:\\WINDOWS\\system32\\drivers\\etc\\hosts. Add a line for each host:

# Bunch of stuff
# ...       localhost       alpha.localhost.com #domain name to experiment with       beta.localhost.com #domain 2       gamma.localhost.com #domain 3


Unfortunatly the Visual Studio built-in web server doesn't work. It doesn't give the application any clues about which domain name the browseris accessing.

Implement ISitesSource

The multiple hosts features requries your root page or 2:nd level pages to implement N2.Web.ISitesSource. The interfaces defines a method that returns information about the web site's start pages and which domain name they should respond to, e.g.:

[N2.Definition("Start Page")]
public class StartPage : TextPage, N2.Web.ISitesSource
    [N2.Details.EditableTextBox("Host", 100)]
    public virtual string Host
        get { return (string)(GetDetail("Host") ?? string.Empty); }
        set { SetDetail("Host", value, string.Empty); }

    public IEnumerable<N2.Web.Site> GetSites()
        yield return new N2.Web.Site(Parent.ID, ID, Host);

    public override string IconUrl
        get { return "~/Edit/img/ico/page_world.gif"; }

Change web.config

Finally you'll need to configure the N2 engine to enable multiple hosts:

    <hosts multipleSites="true"...


The templates are already set up to support multiple sites. You'll just need to set the host name for each start page. If you download the source code there is an example where this can be examined without all of the other noise in the templates. Good luck and let me know if you experience any problems.