[英]Publishing to IIS uses wrong appSettings.json
I have a .NET Core 2.1 web API i am hosting locally with IIS.我有一个 .NET Core 2.1 web API 我在本地托管 Z5DA5ACF461B4EFB27E76EC861065ZB。 I have two child appSettings.json files, Development and Production.
我有两个子 appSettings.json 文件,开发和生产。 I have also created these environments within my project.
我还在我的项目中创建了这些环境。 My publishing profile uses
Debug
profile.我的发布配置文件使用
Debug
配置文件。 When I actually debug my code it works perfectly fine.当我实际调试我的代码时,它工作得非常好。
The issue I have is that when I publish to IIS
under a private IP and access it, it seems my code using the wrong appSettings.json file.我遇到的问题是,当我在私有 IP 下发布到
IIS
并访问它时,似乎我的代码使用了错误的 appSettings.json 文件。 I know this because I have different file paths used for different environments and it prints out the one from Production
.我知道这一点,因为我有不同的文件路径用于不同的环境,它会打印出来自
Production
的文件路径。
Even weirder when I physically delete appSettings.Production.json
from my inetput/wwwroot/{MyProject} folder, then Postman cannot even talk to the API and I get a 500 bad request.更奇怪的是,当我从我的 inetput/wwwroot/{MyProject} 文件夹中物理删除
appSettings.Production.json
时, Postman甚至无法与ZDB974238714CA8DE634A7CE1D0803A14FZ交谈,我收到了一个糟糕的请求。 Maybe I am not configuring or linking correctly?也许我没有正确配置或链接? This is my first time working with environments.
这是我第一次使用环境。
I have lost about 4 hours on this and I am losing it...我已经失去了大约 4 个小时,我正在失去它......
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(ConfigConfiguration)
.UseStartup<Startup>();
static void ConfigConfiguration(WebHostBuilderContext ctx, IConfigurationBuilder config)
{
config.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appSettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appSettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
}
Any more info required, do let me know!需要更多信息,请告诉我!
Ensure to set the ASPNETCORE_ENVIRONMENT
environment variable on the server, see Use multiple environments in ASP.NET Core .确保在服务器上设置
ASPNETCORE_ENVIRONMENT
环境变量,请参阅在 ASP.NET Core 中使用多个环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.