只为成功找方向,不为失败找借口

每天都不能停止前进的脚步
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
问:
.Net Core: Application startup exception: System.IO.FileNotFoundException: 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();
}