ASP.NET Core web service does not load appsettings.json into configuration










7















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:



enter image description here



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...










share|improve this question



















  • 2





    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






  • 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















7















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:



enter image description here



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...










share|improve this question



















  • 2





    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






  • 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













7












7








7


1






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:



enter image description here



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...










share|improve this question
















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:



enter image description here



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:18







wlyles

















asked Nov 13 '18 at 23:32









wlyleswlyles

1,3321328




1,3321328







  • 2





    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






  • 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





    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






  • 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












2 Answers
2






active

oldest

votes


















6














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.






share|improve this answer
































    2














    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.






    share|improve this answer






















      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
      );



      );













      draft saved

      draft discarded


















      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









      6














      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.






      share|improve this answer





























        6














        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.






        share|improve this answer



























          6












          6








          6







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 23:47

























          answered Nov 13 '18 at 23:44









          DavidGDavidG

          69.2k9110126




          69.2k9110126























              2














              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.






              share|improve this answer



























                2














                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.






                share|improve this answer

























                  2












                  2








                  2







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 23:57









                  GregGreg

                  8,71523261




                  8,71523261



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Top Tejano songwriter Luis Silva dead of heart attack at 64

                      ReactJS Fetched API data displays live - need Data displayed static

                      政党