As described in the introduction, this site hosts sub sites. Since some of these are run on an
ASP .NET Core hosting model, we run into a problem hosting multiple sites on one domain.
If the host site would be a
Blazor ASP .NET Core hosted model, when trying to access another sub site that also runs
ASP .NET Core we would hit a
404 error, since the host cannot find the page that is in the sub site. The host doesn’t know that the page requested is actually a sub site and has it’s own hosting model.
To counter this problem I made the host a static
HTML file that has links to the sub sites. (Other hosting models may work e.g. a
Razor pages ASP .NET Core model may work correctly since it reloads the page and doesn’t intercept the navigation as
Blazor does – I did not tested this since I wanted to host with a
With the host setup now as a static
HTML file, we still run into errors when trying to host multiple sub sites that are hosted in
ASP .NET Core here is a live example:
The problem here is that we have sibling apps that both think they own the full domain (sound familiar?!?) each site is trying to use the navigation and they both can’t run together.
The solution to this is to edit the
web.config file and tell the hosting model that it is running
OutOfProcess and therefore doesn’t have full command of the domain. It would look something like this:
This enabled all the sub sites to work correctly and we no longer hit the above errors.
I wanted to test creating tabs in Blazor (to be discussed in a future post), therefore I tested setting up the host site as a static
HTML page that shows an
iframe with full height and width. The
iframe contains a sub site that has the content I wanted to display on the home page.
There were a few problems with this approach:
- This caused the page to have an additional load time, since the frame only gets loaded once the rest of the page has been loaded. Since in this instance the frame is the full height and width of the page the screen remains blank until the frame has loaded.
- When navigating to a sub page within the
iframe, if the cache was cleared (e.g. the tab goes to sleep to save resources), the page would then reload back to the home page since it doesn’t know about any navigations done within the
- When reloading the page you loose where you’re up to. In regular web pages if you reload half way down the browser will reload in that position. If it is within an
iframethe page reloads but doesn’t keep your place within the frame.
Therefore I returned to just using a static
HTML page. If you wish to see the above in action you can view the home page within the
iframe with all the problems here.