Site definitions cannot be handled in config any longer since 7.5 - to the despair of many developers. To modify these settings in a non-interactive way you have to either go through sql (hack the tables directly), use the SiteDefinitionRepository API or by using a hidden cmdlet Set-EPiSiteDefinition (which I haven't been able to find anywhere). It is only briefly mentioned in a comment here: http://world.episerver.com/blogs/Johan-Bjornfot/Dates1/2013/12/Multisite-feature-in-EPiServer-75/. Please post your findings :)
Thanks Johan. Changing the details in the database isn't an option as both sites are using the same database.
I have come up with the following code to be placed in Global.asax and have tested it myself. It works fine but it hasn't been tested by our tester to check different scenarios.
private void Application_BeginRequest(object sender, EventArgs e) { var siteDefinition = SiteDefinition.Current.CreateWritableClone(); siteDefinition.SiteUrl = new Uri(GetSiteUrlFromConfig()); SiteDefinition.Current = siteDefinition; }
Hope it helps other developers.
Replicated database? Both sites using the same database? Could you please describe your scenario a little more in detail? You know you can have multiple site definitions in the same database, right? And they can all have distinct urls. Setting the site definition in each request sounds like a bad decision - as it will most likely affect performance.
Replicated database where one of the databases is fail over so practically it will be the same database.
I have added multiple urls for the site so there is no problem serving the site to the public but the issue occurs in the episerver backend as the url of the page editing tool points to the main URL.
I am not sure what you mean by multiple site definitions. If you mean adding a new site from the admin area then I tried that and it won't work if you want the same start page for both URLs.
For failover purposes, usually the replicated database is not in use. But if I interpret you correctly, each front server has their own copy of the database? That's a scenario I have never encountered before.
"Page editing tool points to main URL" - even when you access the backend through the backend url?
Multiple sites can have the same start page, yes. What do you mean with "it won't work"? What are the symptoms? Perhaps you've not succeeded in saving the settings? For some reason, it's easy to forget "Save" to persist the changes in that page, even though the UI reflects the changes. My changes have been lost a couple of times due to this :-|
So let's say I have one authoring instance and one content delivery. Both of them point to the same database. They have the following URLs
http://cms1.authoring/
http://cms1.web/
and I have similar set up for failover with replicated database.
http://cms2.authoring/
http://cms2.web/
I can only put one of the authoring URLs as the main URL. If I have http://cms1.authoring/ as main URL browse http://cms2.authoring/ the pages in episerver editing tool iframe will be pointing to http://cms1.authoring/ .
When I try adding http://cms2.authoring/ as a second site then it won't let me save as they both have the same start page. It gives me an error saying something like multiple sites can't have the same start page.
Thanks for the clarification! A bit curious why you have chosen to have different urls for the failover? If you have a load-balancer, it's just a configuration issue to have it go to a failover site.
I now see that what you're trying to do is not to add a second site really but an extra set of host headers. It IS the same site really, it's just different urls. So that explains why you get the error. Instead of adding a second site, you need to add them as host urls. That should clear up the mess also with the editing tool.
Oh that is what I have done. I have added the second URL as a host URL but this causes the issue of the editing tool not working as expected.
How much of performance issue is caused if use the code above? Is there a better place to execute that code and change the site url to reduce the performance hit?
I understand that site URL has been moved to database from episerver.config . This is causing an issue as we are using a database that is replicated in a load balanced environment. Is there any way to move the site url back to config to resolve this issue?