How to setup two nested web sites with Kentico CMS

Another topic I am often asked and when the clients try it on their own, they get confused sometimes. So hopefully this will end all the confusion, and you will learn what is the right way to do this.
Hi everybody,

Nested web site (project) may be a difficult thing to set up when you are not too familiar with how ASP.NET works. The usual solution you try is following in the file system:

Inetpub/wwwroot/KenticoCMS1 (first web site from Web installer)
Inetpub/wwwroot/KenticoCMS1/KenticoCMS2 (second web site from Web installer)

Obviously, these two applications are ovelapping and the inner may experience some issues, especially with the configuration file.

That's why I am not recommending this as the option you should choose. Not only for the reason of working web sites, but also for the reason of having the applications mixed together if you want to backup only the outer project or move one project somewhere else.

What is the recommended way?

Here is what I recommend. First, install these two projects into two independent, not overlapping directories, and choose the names that won't be the same as the names in the URL (to be 100% sure that what you later set in IIS is not physical directory but the virtual one). So you install like this:

Inetpub/wwwroot/NestedWeb/Web1 (first web site from Web installer)
Inetpub/wwwroot/NestedWeb/Web2 (second web site from Web installer)

So you have two completely independent projects

IIS configuration

Now go to the IIS and create two virtual directories:

[Default web site]/KenticoCMS1 (pointing to physical directory Web1)
[Default web site]/KenticoCMS1/KenticoCMS2 (child directory pointing to physical directory Web2)

So we have two independent projects, configured as nested only in IIS using virtual directories. That's much better.

Run the web sites

Now if you go to the web sites (or install them) you can see you have two independent web sites which you can configure also independently and they are working fine.

Unless ...

Troubleshooting the web.config collisions

You may come to the point, where you want to set up staging from one site to another. Because staging (WSE3 in particular) has some sections in the web.config that collide, because obviously, you cannot have the same section of web.config twice in the config file and the config files are inherited within the IIS virtual directories structure (even when the projects are not nested on the file system).

So if we configure staging from site KenticoCMS1 to site KenticoCMS1/KenticoCMS2 (see details on how to configure the staging at, the inner project may have issues with the configuration for WSE, you would get an error like this:

The imporant part here is that "The username token has already been added", that means that some of the configuration is duplicit.

User name token authentication is defined in the policy file which is referenced from the section <microsoft.web.services3>, so remove the whole section <microsoft.web.services3> from the web.config of the inner project (Web2). One configuration is enough and it gets from the parent web.config. Do not remove it from the Web1 (outer) project since we need this configuration for both we sites.

And now it suddenly works! Easy, wasn't it?

That's it

This is pretty much it. It is possible that you get the similar errors or have to deal with the inheritance of the values in web.config in other sections. I am not able to tell you which ones that would be, it may even be only this one, but you always get the error which will tell you what is going on.

In case you have some troubles with some configuration sections, you may always use tags <clear /> or <remove ... /> to throw out the inherited values and be able to add your own for nested project(s).

This concept should work for any level of the web sites.

Final word - What are the options for configuring the web sites in IIS:
  • Individual web sites, each one with its own project: (Web site 1)/ and (Web site 2)/
  • Standalone projects, each one in its own virtual directory: (Default web site)/KenticoCMS1 and (Default web site)/KenticoCMS2
  • Nested projects on the virtual directory levels: (Default web site)/KenticoCMS1 and (Default web site)/KenticoCMS1/KenticoCMS2
  • Nested projects on the site / virtual directory levels: (Default web site)/ and (Default web site)/KenticoCMS2
And that pretty much gives you the option to do anything. The only limitation here is that if the projects are nested (the option described in this post), you cannot use single web site instance in file system but you have to have two for the reason of different web.config. With other options, you may use the same project for different sites (URLs)

Bonus (and last) information

If you are using the same project physical instance with multiple virtual directories, you may use different web.config settings (AppSettings and ConnectionStrings) for each virtual directory by creating localized keys like this:
  • Default (global) one: <add name="CMSConnectionString" connectionString="..."/>
  • Local for VD KenticoCMS1: <add name="/KenticoCMS1:CMSConnectionString" connectionString="..."/>
  • Local for VD KenticoCMS2: <add name="/KenticoCMS2:CMSConnectionString" connectionString="..."/>
If you use our SettingsHelper class (from CMS.SettingsProvider namespace), you can get the same functionality for your own keys.

And that's all, see you at my next post.
Share this article on   LinkedIn

Martin Hejtmanek

Hi, I am the CTO of Kentico and I will be constantly providing you the information about current development process and other interesting technical things you might want to know about Kentico.


Martin Hejtmanek commented on

Raymond. Let me know the errors or send them to support

Raymond commented on

Hi, useful post , but when i tried it the web.config couldn't stop throwing errors, i think mainly conflict with the outer site.
system config:
-Win 7 Ultimate
-IIS 7.5
-ASP.NET 3.5
-Outer Site (Kentico 4)
-Inner Site (Kentico 5.5)