MVC multiple sites issue

Sean Sartell asked on April 26, 2022 22:57

I am testing out a multi-site setup with an existing Kentico 12.0.92 installation, but I'm having trouble with the MVC site not picking up the correct site. I want to use the existing admin and presentation sites with the same code base but with new domains. So I went through the admin configuration sites screen and added my other website, entering new (both are of the format dev.xxxx.com and admin.dev.xxxx.com) domains for both the "Site domain name" and "Presentation URL". I have also added the presentation URL to "domain aliases". I then added my domains the bindings of my existing IIS admin and MVC sites.

When I try to load the old site, I'm getting a 404 error as if the content has disappeared. When I break into a controller and look at CMS.SiteProvider.SiteContext.CurrentSite, it has the wrong site name but with the correct admin and presentation URLs. If I change the new site presentation URL to be "2dev.xxxx.com", the old site starts working again.

If I change both domains to be "www.xxxx.com" (thinking maybe dev. was breaking something), the old site works fine, but the new site gives me an A/B Testing licensing errors even though that module is not assigned to that site. If I break into the controller again, the CMS.SiteProvider.SiteContext.CurrentSite has the right site name, but wrong URLs, as if it's trying to load the old site which does have the A/B Testing module assigned.

Why can't Kentico figure out the correct site? Am I doing something wrong? I've double/triple checked the URLs in my site configs.

Recent Answers


Juraj Ondrus answered on April 27, 2022 07:08

?Have you seen the article on Multisite environment in MVC yet? I hope it helps. However, we do not recommend hosting multiple sites in one instance and one code base - if something goes wrong, then all sites are down.

0 votesVote for this answer Mark as a Correct answer

Sean Sartell answered on April 27, 2022 17:27

All sites going down is an acceptable result in this case, and keeping infrastructure and code updates to a minimum is preferred. If I want to continue down this path, how do I get Kentico to correctly resolve the current site? Basic functionality like .OnCurrentSite() does not work as soon as I enter a second site.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on April 28, 2022 11:36

Could you please describe or provide screen shots what are the admin domain and presentation URLs set for each site in Kentico admin? Then, how is configured your routing to work with these domains and routes?

0 votesVote for this answer Mark as a Correct answer

Sean Sartell answered on April 29, 2022 16:04 (last edited on April 29, 2022 16:05)

I can't share the exact domains for confidential reasons, but they both follow this format:

Site domain name: admin.dev.xxxx.com

Presentation URL: http://www.xxxx.com

Where "xxxx" is different between the two sites. Does MVC routing impact how .OnCurrentSite() or CMS.SiteProvider.SiteContext.CurrentSite work? Is there something the MVC code supposed to manually identify the site based on domain before calls are made to the Kentico APIs?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 2, 2022 10:14

If you have different domains set for each site I do not see a problem - especially if the Presentation URL is set correctly. What is your routing like? How does your MVC app distinguish between the domains? When in admin, do you have the right admin domain in the browser's URL? Isn't it possible you have a different tab with the other admin domain opened? Otherwise, as a workaround you could use .OnSite(< sitename >) in your code

0 votesVote for this answer Mark as a Correct answer

Sean Sartell answered on May 2, 2022 16:14 (last edited on May 2, 2022 16:16)

Thanks for the replies Juraj. I'm not sure I'm following the MVC routing question. Most of my routes look something like this:

route = routes.MapRoute(
    name: "Home",
    url: "{culture}",
    defaults: new { culture = defaultCulture.Name, controller = "Home", action = "Index" },
    constraints: new { culture = new SiteCultureConstraint() }
);
route.RouteHandler = new MultiCultureMvcRouteHandler(defaultCulture);

My app doesn't currently distinguish between the domains because all of the routes will be identical between the sites, it's just different content. I assumed Kentico would see the domain and match the site via the presentation URL and filter content accordingly within .OnCurrentSite(). Is that not the case?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 3, 2022 13:33

I tried it by using the sample Dancing Goat MVC project - I have created a new site, basically export and import of existing site, just set different domains in Kentico admin. Both live sites in the IIS are pointing to the same MVC project and it is working fine. Could you please check the sample Dancing Goat project to see what is different in your case? Or, try reproducing the issue using this project so I can reproduce it as well and take further look what is going on.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.