title: How to HTTPS (SSL) with self-hosted ASP.NET Core 2 app (httpsys)
body: <p>I wrote a little ASP.NET Core 2 application. It runs as a service, so no IIS.  It runs on a PC with Windows 7 SP1.</p>
  
  <pre><code>var host = WebHost.CreateDefaultBuilder(args)
              .UseContentRoot(pathToContentRoot)
              .UseHttpSys(options =&gt;
              {
                  options.Authentication.Schemes = AuthenticationSchemes.None;
                  options.Authentication.AllowAnonymous = true;
                  options.MaxConnections = null;
                  options.MaxRequestBodySize = 30000000;
                  options.UrlPrefixes.Add("http://*:5050");
              })
              .UseStartup&lt;Startup&gt;()
              .UseApplicationInsights()
              .Build();
  
  if (isService)
  {
      host.RunAsService();
  }
  else
  {
      host.Run();
  } 
  </code></pre>
  
  <p>As you can see, I want to listen on port 5050. This is working fine without SSL. </p>
  
  <p>My question is, how can I enable https for my application? Again: No IIS, no Domain-Name (no internet connection). Communication is just inside the internal network, so I want to use a self-signed certificate.</p>
  
  <p>I read the documentation (<a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/httpsys?view=aspnetcore-2.1" rel="noreferrer">HTTP.sys documentation</a>;<a href="https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc725882(v=ws.10)#add-urlacl" rel="noreferrer">Netsh Commands</a>;<a href="https://docs.microsoft.com/en-us/powershell/module/pkiclient/new-selfsignedcertificate?view=win10-ps" rel="noreferrer">New-SelfSignedCertificate</a>), but there is always something different to my situation (they use Krestel, or it is for using IIS). Also, I dont know how to get the App-ID (needed for netsh) for my Application. I tryed this: <a href="https://stackoverflow.com/questions/502303/how-do-i-programmatically-get-the-guid-of-an-application-in-net2-0#502327">StackOverflow Get GUID</a> but it doesn't work.</p>
  
  <pre><code>var assembly = typeof(Program).Assembly;
  
  // following line produces: System.IndexOutOfRangeException
  var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
  
  var id = attribute.Value;
  Console.WriteLine(id);
  </code></pre>
  
  <p>So I am a bit confused about all the possabilitys and different configurations. And the docs don't consider my specific case.</p>
  
  <p>I created a certificate, and I guess I need to store it on the "my" Store. (Where is that? cert:\LocalMachine\My) And then I need to assign my Applicaion ID and Port to it. </p>
  
  <p>But I have no idea how to do that exactly. Can anyone help?</p>