title: Owin self host console application with https support (no web api, no SignalR)
body: <p>With SslStream and socket, I've developed a https web server from scratch.
  I can apply a certificate to the stream from C# code and deal with the requests.</p>
  
  <p>However, I didn't figure out how to do this with Owin.
  Does any one know how to bind a certificate to a self hosted console application?</p>
  
  <p><em>Example:</em></p>
  
  <pre><code>// Bind the below certificate to Owin host
  var certificate = new X509Certificate2("server.pfx", "password");
  </code></pre>
  
  <p>Please refer to the existing Owin host code below for details:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Microsoft.Owin.Hosting;
  using AppFunc = System.Func&lt;System.Collections.Generic.IDictionary&lt;string, object&gt;, System.Threading.Tasks.Task&gt;;
  
  namespace Owin.Startup
  {
      class Program
      {
          static void Main(string[] args)
          {
              int port = 8888;
              string url = $"http://localhost:{port}";
              using (WebApp.Start&lt;Startup&gt;(url))
              {
                  Console.WriteLine($"Hosted: {url}");
                  Console.ReadLine();
              }
          }
      }
  
      public class Startup
      {
          private IAppBuilder app;
          public void Configuration(IAppBuilder app)
          {
  #if DEBUG
              app.UseErrorPage();
  #endif
  
              app.Use(new Func&lt;AppFunc, AppFunc&gt;(next =&gt; (async env =&gt;
              {
                  Console.WriteLine("Begin Request");
                  foreach (var i in env.Keys)
                  {
                      Console.WriteLine($"{i}\t={(env[i] == null ? "null" : env[i].ToString())}\t#\t{(env[i] == null ? "null" : env[i].GetType().FullName)}");
                  }
                  if (next != null)
                  {
                      await next.Invoke(env);
                  }
                  else
                  {
                      Console.WriteLine("Process Complete");
                  }
                  Console.WriteLine("End Request");
              })));
  
              app.UseWelcomePage("/");
  
              this.app = app;
          }
  
  
      }
  
  }
  </code></pre>