Different url based on development environment with C# MVC

后端 未结 7 1648
眼角桃花
眼角桃花 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

    If you want to use DotNet Core or want to switch to it, then it is best to implement it's environment configuration abilities.

    Documentation on official site: Working with multiple environments and Configuration in ASP.NET Core

    Here is a good example.

    var builder = new ConfigurationBuilder()
        SetBasePath(hostEnv.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{hostEnv.EnvironmentName}.json", optional: true, reloadOnChange: true);
    

    All you need is to define 3 different appsettings files. And set ASPNETCORE_ENVIRONMENT in your system there you want to do your tests or developing.

    Or you can use env.IsEnvironment("environmentname") to check something in runtime.

    0 讨论(0)
提交回复
热议问题