Different url based on development environment with C# MVC

后端 未结 7 1676
眼角桃花
眼角桃花 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 15:14

    The solutions proposed are good but a lot of overhead just to switch one url IMHO.

    I would take the environment variable approach and set the url accordingly.

    Contact.cshtml

    @{
        var env = Environment.GetEnvironmentVariable("MY_APP_ENV");
        var url = env == "prod" ? "http://qa.solution.company.com/Contact/" :
                  env == "qa"   ? "http://solution.company.com/Contact/" :
                                  "http://localhost:88/contact/";
    }
    
    Contact Us
    

    If this is a big project and you can invest some time, I would put this in appSettings and set up parameters.xml for each environment and use it during deployment.

提交回复
热议问题