title: Configure ASP.NET Core 2.0 Kestrel for HTTPS
body: <p>TL;DR What is today the correct way to setup HTTPS with ASP.NET Core 2.0?</p>
  
  <p>I would like to configure my project to use https and a certificate like they have shown at <a href="https://www.youtube.com/watch?v=h9hlN0DOKRM&amp;t=1342s" rel="noreferrer">BUILD 2017</a>. I have tried several settings but nothing worked. After some research, I am even more confused. It seems that there are many ways to configure URLs and ports… I have seen <code>appsettings.json</code>, <code>hosting.json</code>, via code, and in <code>launchsettings.json</code> we can also set the URL and port.</p>
  
  <p>Is there a "standard" way to do it?</p>
  
  <p>Here is my <code>appsettings.development.json</code></p>
  
  <pre><code>{
    "Kestrel": {
      "Endpoints": {
        "Localhost": {
          "Address": "127.0.0.1",
          "Port": "40000"
        },
        "LocalhostWithHttps": {
          "Address": "127.0.0.1",
          "Port": "40001",
          "Certificate": {
            "HTTPS": {
              "Source": "Store",
              "StoreLocation": "LocalMachine",
              "StoreName": "My",
              "Subject": "CN=localhost",
              "AllowInvalid": true
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>But it always takes the url and the port from <code>launchsettings.json</code> when I start from the command line with <code>dotnet run</code> or when I start with the debugger from Visual Studio.</p>
  
  <p>This is my <code>Program.cs</code> and <code>Startup.cs</code></p>
  
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          BuildWebHost(args).Run();
      }
  
      public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .Build();
  }
  
  public class Startup
  {
      public IConfiguration Configuration { get; }
      public string Authority { get; set; } = "Authority";
      public string ClientId { get; set; } = "ClientId";
  
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;MvcOptions&gt;(options =&gt; options.Filters.Add(new RequireHttpsAttribute()));
  
          JsonConvert.DefaultSettings = () =&gt; new JsonSerializerSettings() {
              NullValueHandling = NullValueHandling.Ignore
          };
  
          services.AddSingleton&lt;IRepository, AzureSqlRepository&gt;(x =&gt; new AzureSqlRepository(Configuration.GetConnectionString("DefaultConnection")));
          services.AddSingleton&lt;ISearchSplitService, SearchSplitService&gt;();
  
          services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
              .AddJwtBearer(options =&gt; new JwtBearerOptions {
                  Authority = this.Authority,
                  Audience = this.ClientId
          });
  
          services.AddMvc();
      }
  
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
              app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions() { HotModuleReplacement = true, ReactHotModuleReplacement = true, HotModuleReplacementEndpoint = "/dist/__webpack_hmr" });
          }
  
          app.UseStaticFiles();
          app.UseAuthentication();
  
          app.UseMvc(routes =&gt; {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{id?}");
  
              routes.MapSpaFallbackRoute(
                  name: "spa-fallback",
                  defaults: new { controller = "Home", action = "Index" });
          });
      }
  }
  </code></pre>
  
  <p>As I have said, I was not able to get it working in any constallation. What is today the correct way to setup HTTPS with ASP.NET Core 2.0?</p>