This project has moved and is read-only. For the latest updates, please go here.

What is the way to host an application through https

Mar 29, 2013 at 1:56 PM
Edited Mar 29, 2013 at 1:59 PM

I have the following Program.cs file to host my Web API application for now:
class Program {

    private const string HostUri = "http://localhost:10381/";
    private const string HostUriHttps = "";

    static void Main(string[] args) {

        // TODO: Open both URIs (HTTP and HTTPS).
        // TODO: Use new ASP.NET Web API integration package. 
        //       They have different API.

        using (WebApplication.Start<Startup>(HostUri)) {

            Console.WriteLine("Started on ");
It works great. However, I want to expose the service over following two endpoints and with one of them, I need to configure the SSL cert:
What is the way to do this with katana today? I saw that there is a tool called CertInstaller inside the solution but I figured that it would be better to ask first.

These following are the packages I have:
<?xml version="1.0" encoding="utf-8"?>
  <package id="EntityFramework" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="0.21.0-pre" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Diagnostics" version="0.21.0-pre" targetFramework="net45" />
  <package id="Microsoft.Owin.Host.HttpListener" version="0.21.0-pre" targetFramework="net45" />
  <package id="Microsoft.Owin.Hosting" version="0.21.0-pre" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
Mar 29, 2013 at 3:42 PM
Let me separate this into two:

1) Multiple addresses: You can do multiple addresses via one server instance, but today the only way to add the second address is via IAppBuilder.Properties["host.Addresses"]. We're working on an update for WebApplication.Start to support multiple addresses.

2) HTTPS: In code all you have to do is supply a URI with the HTTPS scheme. However, the only way to configure the certificate is via netsh.exe. Unfortunately this is an operating system limitation so all we can do is give you good instructions. Try the following and let me know how they work for you:


GUI Tools:
Marked as answer by Tratcher on 5/21/2014 at 2:13 PM
Mar 29, 2013 at 5:38 PM
Hi Chris,

Thank you very much for the info. This will get me up and running.

Mar 31, 2013 at 11:48 AM
Hi Chris,

It was really hard to figure out how to register multiple addresses. Haven't configured HTTPS but I got multiple address registration working at least with the following code:
    private void RegisterAddresses(IAppBuilder app) {

        Uri HostUri = new Uri("http://localhost:16897/");
        Uri HostUriHttps = new Uri("https://localhost:44567/");

        // NOTE: OwinServerFactoryAttribute.Create method and 
        //       OwinHttpListener.Start should give you a hint on how
        //       to register the addresses.
        app.Properties["host.Addresses"] = new List<IDictionary<string, object>> {
            new Dictionary<string, object> { 
                { "scheme", HostUri.Scheme },
                { "host", HostUri.Host },
                { "port", HostUri.Port.ToString()  }

            new Dictionary<string, object> { 
                { "scheme", HostUriHttps.Scheme },
                { "host", HostUriHttps.Host },
                { "port", HostUriHttps.Port.ToString()  }
Which's a really hassle as you can see :) looking forward to the option that will be added to WebApplication.Start to support this.
Apr 29, 2014 at 11:02 AM

Did you get any further with this ? We also have the requirement to have both https and http endpoint's registered.

We've got your example code working for two http endpoint but couldn't get it to work with one http / one https.

It's difficult to debug as it just seems to not listening.
Apr 29, 2014 at 5:08 PM
Multiple urls can now be configured via the StartOptions.Urls collection:

Here are some updated instructions for HTTPS hosting:

Try getting the site working with just HTTPS first, that's the hard one.
Marked as answer by Tratcher on 5/21/2014 at 2:14 PM