在ASP.NET Core中使用自定义环境

时间:2019-01-30 15:23:26

标签: visual-studio-2017 environment-variables

我的appsettings文件确实起作用,我看到它们根据我使用的启动配置文件被使用,但是我的本地主机配置文件不起作用,因为它似乎在我使用的实际框架中不存在。无论如何,是否要添加一个自定义变量,例如“ localhost”?

My appsettings files does work I see them being used according to which launching profile I use however,,,

My Localhost profile doesn't work because it doesn't seems to exist in the actual Framework I use. Is there anyway to add a custom one such as "localhost"?

编辑:

enter image description here

我的CSS无法加载

enter image description here

谢谢!

1 个答案:

答案 0 :(得分:0)

在您的Program.cs,呼叫添加到config.AddJsonFile()

    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddJsonFile("appsettings.Localhost.json", optional: true);
            })
            .UseStartup<Startup>();