Try our conversational search powered by Generative AI!

Update site URL in migrated project

EVT
EVT
Vote:
 

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?

#305106
Jul 13, 2023 9:08
Vote:
 

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

#305108
Jul 13, 2023 10:27
Vote:
 

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.

#305444
Jul 20, 2023 8:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.