Different url based on development environment with C# MVC

后端 未结 7 1611
眼角桃花
眼角桃花 2021-02-15 14:25

I have two MVC web applications, a www.company.com and a solution.company.com

The website www.company.com include links to solution.company.com/Contact but how can I set

7条回答
  •  清酒与你
    2021-02-15 14:55

    If for some reason you do not have an automated deploy system that lets you specify per-environment variables (like Octopus as mentioned in previous answers) there are a couple of other options.

    1: Put your settings in a machine.config file for each environment and deploy that config to the appropriate servers.

    2: Put your relationships in your config file:

      
        
        
        
        
      
    

    then ask for the settings by hostname in your controller:

    var contactLink = ConfigurationManager.AppSettings[$"contact-for{Request.Url.Host}"]
    

    and pass it to your model.

    As you don't have different configurations to switch between, to test this approach you can change your hosts file (c:\System32\drivers\etc\hosts) to fake being each of the environments

    127.0.0.1  localhost
    127.0.0.1  qa.company.com
    127.0.0.1  company.com
    127.0.0.1  www.company.com
    

    Then comment out or remove the non-localhost entries to connect to the real servers.

提交回复
热议问题