ASP.NET Core web service does not load appsettings.json into configuration
I have an ASP.NET Core 2.1 Web Application with Razor Pages which has AAD authentication information defined in the appsettings.json
file (courtesy of the default application template - see below on how I got there). However, when trying to configure the authentication in Startup.cs
the configuration does not have any of the config values from my appsettings.json
. If I inspect the IConfiguration
object in the debugger then it appears to only have the environment variable configurations:
Here's the Startup.ConfigureServices
method where the issue lies:
public void ConfigureServices(IServiceCollection services)
services.Configure<CookiePolicyOptions>(options =>
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
);
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options =>
// This is from the default template. It should work, but the relevant settings aren't there so options isn't populated.
this.Configuration.Bind("AzureAd", options);
// This of course works fine
options.Instance = "MyInstance";
options.Domain = "MyDomain";
options.TenantId = "MyTenantId";
options.ClientId = "MyClientId";
options.CallbackPath = "MyCallbackPath";
);
services.AddMvc(options =>
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
And the service configuration in case it's important (note that this is being built on top of a service fabric stateless service):
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
return new ServiceInstanceListener
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on url");
return new WebHostBuilder()
.UseKestrel(opt =>
int port = serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint").Port;
opt.Listen(IPAddress.IPv6Any, port, listenOptions =>
listenOptions.UseHttps(GetCertificateFromStore());
listenOptions.NoDelay = true;
);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
))
;
To create this service, I used the wizard in VS2017. I selected an existing service fabric project (.sfproj
) and chose Services > Add > New Service Fabric Service
and chose Stateless ASP.NET Core [for .NET Framework]
, then on the next page I chose Web Application
(the one with Razor Pages, not MVC) and clicked Change Authentication
where I chose Work or School Accounts
and entered my AAD info. The only changes I have made to this template were adding the code inside the call to AddAzureAD
in Startup.ConfigureServices
and setting the appsettings.json
files to always be copied to the output directory.
Why doesn't the appsettings.json
file get loaded into the configuration? As I understand, this is supposed to happen by default, but something seems to be missing...
c# asp.net asp.net-core
add a comment |
I have an ASP.NET Core 2.1 Web Application with Razor Pages which has AAD authentication information defined in the appsettings.json
file (courtesy of the default application template - see below on how I got there). However, when trying to configure the authentication in Startup.cs
the configuration does not have any of the config values from my appsettings.json
. If I inspect the IConfiguration
object in the debugger then it appears to only have the environment variable configurations:
Here's the Startup.ConfigureServices
method where the issue lies:
public void ConfigureServices(IServiceCollection services)
services.Configure<CookiePolicyOptions>(options =>
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
);
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options =>
// This is from the default template. It should work, but the relevant settings aren't there so options isn't populated.
this.Configuration.Bind("AzureAd", options);
// This of course works fine
options.Instance = "MyInstance";
options.Domain = "MyDomain";
options.TenantId = "MyTenantId";
options.ClientId = "MyClientId";
options.CallbackPath = "MyCallbackPath";
);
services.AddMvc(options =>
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
And the service configuration in case it's important (note that this is being built on top of a service fabric stateless service):
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
return new ServiceInstanceListener
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on url");
return new WebHostBuilder()
.UseKestrel(opt =>
int port = serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint").Port;
opt.Listen(IPAddress.IPv6Any, port, listenOptions =>
listenOptions.UseHttps(GetCertificateFromStore());
listenOptions.NoDelay = true;
);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
))
;
To create this service, I used the wizard in VS2017. I selected an existing service fabric project (.sfproj
) and chose Services > Add > New Service Fabric Service
and chose Stateless ASP.NET Core [for .NET Framework]
, then on the next page I chose Web Application
(the one with Razor Pages, not MVC) and clicked Change Authentication
where I chose Work or School Accounts
and entered my AAD info. The only changes I have made to this template were adding the code inside the call to AddAzureAD
in Startup.ConfigureServices
and setting the appsettings.json
files to always be copied to the output directory.
Why doesn't the appsettings.json
file get loaded into the configuration? As I understand, this is supposed to happen by default, but something seems to be missing...
c# asp.net asp.net-core
2
WebHostBuilder
doesn't loadappsettings.json
by default, you need to manually callAddJsonFile
.
– DavidG
Nov 13 '18 at 23:36
Well I'll be damned. Sure enough, that solved my problem. Instead of doing that I actually replacednew WebHostBuilder()
withWebHost.CreateDefaultBuilder()
, but why the template doesn't work out of the box is beyond me. Thanks!
– wlyles
Nov 13 '18 at 23:45
1
Yes, that will also load the config. I believe it was change in 2.0, perhaps your template is an older one?
– DavidG
Nov 13 '18 at 23:46
It's possible. Who knows when the templates were last updated, but they're apparently not tested very thoroughly
– wlyles
Nov 13 '18 at 23:50
add a comment |
I have an ASP.NET Core 2.1 Web Application with Razor Pages which has AAD authentication information defined in the appsettings.json
file (courtesy of the default application template - see below on how I got there). However, when trying to configure the authentication in Startup.cs
the configuration does not have any of the config values from my appsettings.json
. If I inspect the IConfiguration
object in the debugger then it appears to only have the environment variable configurations:
Here's the Startup.ConfigureServices
method where the issue lies:
public void ConfigureServices(IServiceCollection services)
services.Configure<CookiePolicyOptions>(options =>
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
);
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options =>
// This is from the default template. It should work, but the relevant settings aren't there so options isn't populated.
this.Configuration.Bind("AzureAd", options);
// This of course works fine
options.Instance = "MyInstance";
options.Domain = "MyDomain";
options.TenantId = "MyTenantId";
options.ClientId = "MyClientId";
options.CallbackPath = "MyCallbackPath";
);
services.AddMvc(options =>
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
And the service configuration in case it's important (note that this is being built on top of a service fabric stateless service):
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
return new ServiceInstanceListener
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on url");
return new WebHostBuilder()
.UseKestrel(opt =>
int port = serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint").Port;
opt.Listen(IPAddress.IPv6Any, port, listenOptions =>
listenOptions.UseHttps(GetCertificateFromStore());
listenOptions.NoDelay = true;
);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
))
;
To create this service, I used the wizard in VS2017. I selected an existing service fabric project (.sfproj
) and chose Services > Add > New Service Fabric Service
and chose Stateless ASP.NET Core [for .NET Framework]
, then on the next page I chose Web Application
(the one with Razor Pages, not MVC) and clicked Change Authentication
where I chose Work or School Accounts
and entered my AAD info. The only changes I have made to this template were adding the code inside the call to AddAzureAD
in Startup.ConfigureServices
and setting the appsettings.json
files to always be copied to the output directory.
Why doesn't the appsettings.json
file get loaded into the configuration? As I understand, this is supposed to happen by default, but something seems to be missing...
c# asp.net asp.net-core
I have an ASP.NET Core 2.1 Web Application with Razor Pages which has AAD authentication information defined in the appsettings.json
file (courtesy of the default application template - see below on how I got there). However, when trying to configure the authentication in Startup.cs
the configuration does not have any of the config values from my appsettings.json
. If I inspect the IConfiguration
object in the debugger then it appears to only have the environment variable configurations:
Here's the Startup.ConfigureServices
method where the issue lies:
public void ConfigureServices(IServiceCollection services)
services.Configure<CookiePolicyOptions>(options =>
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
);
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options =>
// This is from the default template. It should work, but the relevant settings aren't there so options isn't populated.
this.Configuration.Bind("AzureAd", options);
// This of course works fine
options.Instance = "MyInstance";
options.Domain = "MyDomain";
options.TenantId = "MyTenantId";
options.ClientId = "MyClientId";
options.CallbackPath = "MyCallbackPath";
);
services.AddMvc(options =>
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
And the service configuration in case it's important (note that this is being built on top of a service fabric stateless service):
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
return new ServiceInstanceListener
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on url");
return new WebHostBuilder()
.UseKestrel(opt =>
int port = serviceContext.CodePackageActivationContext.GetEndpoint("ServiceEndpoint").Port;
opt.Listen(IPAddress.IPv6Any, port, listenOptions =>
listenOptions.UseHttps(GetCertificateFromStore());
listenOptions.NoDelay = true;
);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
))
;
To create this service, I used the wizard in VS2017. I selected an existing service fabric project (.sfproj
) and chose Services > Add > New Service Fabric Service
and chose Stateless ASP.NET Core [for .NET Framework]
, then on the next page I chose Web Application
(the one with Razor Pages, not MVC) and clicked Change Authentication
where I chose Work or School Accounts
and entered my AAD info. The only changes I have made to this template were adding the code inside the call to AddAzureAD
in Startup.ConfigureServices
and setting the appsettings.json
files to always be copied to the output directory.
Why doesn't the appsettings.json
file get loaded into the configuration? As I understand, this is supposed to happen by default, but something seems to be missing...
c# asp.net asp.net-core
c# asp.net asp.net-core
edited Nov 14 '18 at 16:18
wlyles
asked Nov 13 '18 at 23:32
wlyleswlyles
1,3321328
1,3321328
2
WebHostBuilder
doesn't loadappsettings.json
by default, you need to manually callAddJsonFile
.
– DavidG
Nov 13 '18 at 23:36
Well I'll be damned. Sure enough, that solved my problem. Instead of doing that I actually replacednew WebHostBuilder()
withWebHost.CreateDefaultBuilder()
, but why the template doesn't work out of the box is beyond me. Thanks!
– wlyles
Nov 13 '18 at 23:45
1
Yes, that will also load the config. I believe it was change in 2.0, perhaps your template is an older one?
– DavidG
Nov 13 '18 at 23:46
It's possible. Who knows when the templates were last updated, but they're apparently not tested very thoroughly
– wlyles
Nov 13 '18 at 23:50
add a comment |
2
WebHostBuilder
doesn't loadappsettings.json
by default, you need to manually callAddJsonFile
.
– DavidG
Nov 13 '18 at 23:36
Well I'll be damned. Sure enough, that solved my problem. Instead of doing that I actually replacednew WebHostBuilder()
withWebHost.CreateDefaultBuilder()
, but why the template doesn't work out of the box is beyond me. Thanks!
– wlyles
Nov 13 '18 at 23:45
1
Yes, that will also load the config. I believe it was change in 2.0, perhaps your template is an older one?
– DavidG
Nov 13 '18 at 23:46
It's possible. Who knows when the templates were last updated, but they're apparently not tested very thoroughly
– wlyles
Nov 13 '18 at 23:50
2
2
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
.– DavidG
Nov 13 '18 at 23:36
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
.– DavidG
Nov 13 '18 at 23:36
Well I'll be damned. Sure enough, that solved my problem. Instead of doing that I actually replaced
new WebHostBuilder()
with WebHost.CreateDefaultBuilder()
, but why the template doesn't work out of the box is beyond me. Thanks!– wlyles
Nov 13 '18 at 23:45
Well I'll be damned. Sure enough, that solved my problem. Instead of doing that I actually replaced
new WebHostBuilder()
with WebHost.CreateDefaultBuilder()
, but why the template doesn't work out of the box is beyond me. Thanks!– wlyles
Nov 13 '18 at 23:45
1
1
Yes, that will also load the config. I believe it was change in 2.0, perhaps your template is an older one?
– DavidG
Nov 13 '18 at 23:46
Yes, that will also load the config. I believe it was change in 2.0, perhaps your template is an older one?
– DavidG
Nov 13 '18 at 23:46
It's possible. Who knows when the templates were last updated, but they're apparently not tested very thoroughly
– wlyles
Nov 13 '18 at 23:50
It's possible. Who knows when the templates were last updated, but they're apparently not tested very thoroughly
– wlyles
Nov 13 '18 at 23:50
add a comment |
2 Answers
2
active
oldest
votes
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
. For example:
return new WebHostBuilder()
.UseKestrel(opt =>
//snip
)
.ConfigureAppConfiguration((builderContext, config) =>
config.AddJsonFile("appsettings.json", optional: false);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
Alternatively you can use WebHost.CreateDefaultBuilder
which will load more defaults.
add a comment |
Another approach, would be to manually create the configuration via ConfigurationBuilder
then use the UseConfiguration
method.
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(configuration)
.UseKestrel()
.UseStartup<Startup>();
The primary intent is core to provide a bit of flexibility when implementing, they often error on less is more. You have to explicitly say what you would like, that way the pipeline remains relatively small.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291037%2fasp-net-core-web-service-does-not-load-appsettings-json-into-configuration%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
. For example:
return new WebHostBuilder()
.UseKestrel(opt =>
//snip
)
.ConfigureAppConfiguration((builderContext, config) =>
config.AddJsonFile("appsettings.json", optional: false);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
Alternatively you can use WebHost.CreateDefaultBuilder
which will load more defaults.
add a comment |
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
. For example:
return new WebHostBuilder()
.UseKestrel(opt =>
//snip
)
.ConfigureAppConfiguration((builderContext, config) =>
config.AddJsonFile("appsettings.json", optional: false);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
Alternatively you can use WebHost.CreateDefaultBuilder
which will load more defaults.
add a comment |
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
. For example:
return new WebHostBuilder()
.UseKestrel(opt =>
//snip
)
.ConfigureAppConfiguration((builderContext, config) =>
config.AddJsonFile("appsettings.json", optional: false);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
Alternatively you can use WebHost.CreateDefaultBuilder
which will load more defaults.
WebHostBuilder
doesn't load appsettings.json
by default, you need to manually call AddJsonFile
. For example:
return new WebHostBuilder()
.UseKestrel(opt =>
//snip
)
.ConfigureAppConfiguration((builderContext, config) =>
config.AddJsonFile("appsettings.json", optional: false);
)
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
Alternatively you can use WebHost.CreateDefaultBuilder
which will load more defaults.
edited Nov 13 '18 at 23:47
answered Nov 13 '18 at 23:44
DavidGDavidG
69.2k9110126
69.2k9110126
add a comment |
add a comment |
Another approach, would be to manually create the configuration via ConfigurationBuilder
then use the UseConfiguration
method.
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(configuration)
.UseKestrel()
.UseStartup<Startup>();
The primary intent is core to provide a bit of flexibility when implementing, they often error on less is more. You have to explicitly say what you would like, that way the pipeline remains relatively small.
add a comment |
Another approach, would be to manually create the configuration via ConfigurationBuilder
then use the UseConfiguration
method.
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(configuration)
.UseKestrel()
.UseStartup<Startup>();
The primary intent is core to provide a bit of flexibility when implementing, they often error on less is more. You have to explicitly say what you would like, that way the pipeline remains relatively small.
add a comment |
Another approach, would be to manually create the configuration via ConfigurationBuilder
then use the UseConfiguration
method.
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(configuration)
.UseKestrel()
.UseStartup<Startup>();
The primary intent is core to provide a bit of flexibility when implementing, they often error on less is more. You have to explicitly say what you would like, that way the pipeline remains relatively small.
Another approach, would be to manually create the configuration via ConfigurationBuilder
then use the UseConfiguration
method.
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(configuration)
.UseKestrel()
.UseStartup<Startup>();
The primary intent is core to provide a bit of flexibility when implementing, they often error on less is more. You have to explicitly say what you would like, that way the pipeline remains relatively small.
answered Nov 13 '18 at 23:57
GregGreg
8,71523261
8,71523261
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291037%2fasp-net-core-web-service-does-not-load-appsettings-json-into-configuration%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
WebHostBuilder
doesn't loadappsettings.json
by default, you need to manually callAddJsonFile
.– DavidG
Nov 13 '18 at 23:36
Well I'll be damned. Sure enough, that solved my problem. Instead of doing that I actually replaced
new WebHostBuilder()
withWebHost.CreateDefaultBuilder()
, but why the template doesn't work out of the box is beyond me. Thanks!– wlyles
Nov 13 '18 at 23:45
1
Yes, that will also load the config. I believe it was change in 2.0, perhaps your template is an older one?
– DavidG
Nov 13 '18 at 23:46
It's possible. Who knows when the templates were last updated, but they're apparently not tested very thoroughly
– wlyles
Nov 13 '18 at 23:50