.NET Core The configuration file 'appsettings.json' was not found and is not optional

错误代码

public Startup()
{
var builder = new ConfigurationBuilder().AddJsonFile("AppSetting.json");
Configuration = builder.Build();
}
 
修改
 
public Startup(IHostingEnvironment environment)
{
var builder = new ConfigurationBuilder().SetBasePath(environment.ContentRootPath).AddJsonFile("AppSetting.json");
Configuration = builder.Build();
}
 
 
 

public Startup()
{
var buiider = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("AppSettings.json");
Configuration = buiider.Build();
}

.NET Core The configuration file 'appsettings.json' was not found and is not optional

上一篇:RestTemplate/httpclient请求:请求参数中的特殊字符处理


下一篇:判断手机系统的类型