Hosting Multiple Sites Based on Folder Names

Hosting multiple sites based on Folder names in mojoPortal content management system requires that the master site run as a root Web site. For example, it must have a URL structure like http://hostname/

The child sites will be based on the first folder name after the host name segment like http://hostname/somefolder/

In a default configuration of IIS, a request like http://hostname/site2/ will be handled first by IIS, typically it will look for a Default.aspx file in the folder named somefolder and if it is found it will hand the request off to ASP.NET but if the folder does not exist and/or the file is not there, it will generate a 404 page not found error rather than handing the request to ASP.NET.

So if you want to have it work with urls like http://hostname/site2/ you would need to either make ASP.NET the default handler for all requests or make sure the folder exists and it contains a file named Default.aspx. The Default.aspx file can be just an empty text file, it doesn't need any code or contents in it, its only purpose is to get ASP.NET to handle the request. From there the mojoPortal code detects the folder mapped to the site and serves the correct content. Without doing one of these things, the only way ASP.NET will handle the request is if the url ends with Default.aspx or somepage.aspx where somepage.aspx is an url defined by the site.

How To Create Folder Based Sites

  1. Get the first site working first
  2. Add the following to your user.config file and then touch the web.config.
    <add key="AllowMultipleSites" value="true" />
    <add key="UseFoldersInsteadOfHostnamesForMultipleSites" value="true" />
  3. Go to Administration > Site List in the first site.
  4. Click the Create New Site link.
  5. Enter the Site Title and any other settings you want on the new site and then click the Save button at the bottom of the page.
  6. After you save the new site, some new tabs appear on the settings page for the site, Folder Site Mapping and Features . Click the Folder Site Mapping tab.
  7. Type the name of the folder that will map to the new site and click the Add Folder Mapping button.

    Note that I have mapped a folder named "site2" to the second site. So if my master site is at http://localhost/, I can now open a browser and go to http://localhost/site2/Default.aspx to see the second site.
    Folder names can have only alphanumeric characters and cannot have spaces. Folder names that conflict with existing mojoPortal system folders cannot be used. If you need to block additional folder names from being used you can append them to the ones listed in Web.config DisallowedVirtualFolderNames setting using semicolons to separate the folder names to block.
    If you want the urls to work without the Default.aspx page (i.e. http://somehost/site2) you should also create a physical folder beneath the root site with the same name (ie. "site2" as shown above) and put an empty text file in there named Default.aspx. Otherwise you would need to look into configuring IIS so that all requests are handled by ASP.NET.

  8. Click the "Features" tab and add the features you want available to the site.

Limitations

An important thing to understand when using folder based child sites is that since all the sites share the same host name, they also share the same physical cookie file and the same authentication ticket. In mojoPortal CMS code we mitigate this as much as possible by using site specific cookie names to help keep most of the cookies separate. Since the authentication cookie is shared, if you login to one site it logs you out of any other site running in the same installation if your login name is different. This is because your login name is stored in the authentication ticket which is shared across folder based sub sites. If your login name is the same across sites it will not log you out of the other sites but you will have to login to each site separately. That is, logging into one site doesn't log you into all sites.

The above issue only pertains to folder based sub sites. Sub sites based on host names have different physical cookie files and therefore have no interaction.

Rate this Content 15 Votes