November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi Emilija
I would add the url as a hostname to your production site and then re-copy the database across.
Then when you hit the site the url is there already.
It also sounds like you have something configured to redirect you to the production site, I would check your configuration for any redirects.
Thanks
Paul
In CMS 11 we do this. If you don't have Application Insights or run a multi site installation you need to adjust.
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class HostDefinitionsInitialization : IInitializableModule {
public void Initialize(InitializationEngine context) {
if(ServiceLocator.Current.GetInstance<IDatabaseMode>().DatabaseMode == DatabaseMode.ReadOnly) return;
var address = ConfigurationManager.AppSettings["PrimaryHost"];
var siteDefinitionRepository = ServiceLocator.Current.GetInstance<ISiteDefinitionRepository>();
var siteDefinition = siteDefinitionRepository.List().FirstOrDefault();
if(siteDefinition == null) return;
if(string.IsNullOrWhiteSpace(address)) return;
siteDefinition = siteDefinition.CreateWritableClone();
siteDefinition.Hosts = siteDefinition.Hosts.Select(x => x.CreateWritableClone()).ToList();
foreach (var host in siteDefinition.Hosts.Where(x => x.Type == HostDefinitionType.Primary)) {
host.Name = address;
}
try {
siteDefinitionRepository.Save(siteDefinition);
}
catch (Exception exception) {
var telemetryClient = new TelemetryClient();
telemetryClient.TrackException(exception);
}
}
public void Uninitialize(InitializationEngine context) {
}
}
And in your web.config:
<configuration>
...
<appSettings>
<add key="PrimaryHost" value="hostname"/>
...
Make sure to have a backup of the database on your first run though.
Migrated the project, got the hostname, trying to login, am redirected to the production site (because database is from live).
What is the recommended way to update it to the correct value?