title: Read connection from appsettings.json in .net core 1.1 web api
body: <p>I am create a web api project in .net core 1.1 but problem is when its try to read connectionstring from appsettings.json an exception occurs .</p>
  
  <blockquote>
    <p>System.IO.FileNotFoundException: 'The configuration file
    'appsettings.json' was not found and is not optional. The physical
    path is
    'C:\Test\netCoreWebApi\netCoreWebApi\bin\Debug\netcoreapp1.1\appsettings.json'.'</p>
  </blockquote>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>public class Startup
      {
          public Startup(IHostingEnvironment env)
          {
              var builder = new ConfigurationBuilder()
                  .SetBasePath(env.ContentRootPath)
                  .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                  .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                  .AddEnvironmentVariables();
              Configuration = builder.Build();
          }
  
          public IConfigurationRoot Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContext&lt;NorthWindDBContext&gt;();
              // Add framework services.
              services.AddMvc();
  
              services.AddScoped&lt;ICategory_Product, Category_ProductRepository&gt;();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
          {
              loggerFactory.AddConsole(Configuration.GetSection("Logging"));
              loggerFactory.AddDebug();
  
              app.UseMvc();
          }
      }
  </code></pre>
  
  <p>also eclare connectionstring in DBContext class (may be I am doing wrong here)</p>
  
  <pre><code>protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
          {
              var builder = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
  
              var configuration = builder.Build();
  
              string connectionString = configuration.GetConnectionString("northwindConnection");
              optionsBuilder.UseMySql(connectionString);
  
  
          }
  </code></pre>
  
  <p>so wats the correct way .</p>
  
  <p>please help .</p>