This project has moved. For the latest updates, please go here.

What is the way to host an application through https

Mar 29, 2013 at 12:56 PM
Edited Mar 29, 2013 at 12:59 PM
Hi,

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 = "https://127.0.0.1:44306/";

    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 ");
            Console.ReadKey();
            Console.WriteLine("Stopping");
        }
    }
}
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:
http://localhost:10381/
https://127.0.0.1:44306/
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"?>
<packages>
  <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" />
</packages>
Thanks!
Coordinator
Mar 29, 2013 at 2: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:

Documentation:
http://msdn.microsoft.com/en-us/library/ms733791.aspx
http://sunshaking.blogspot.com/2012/11/https-communication-httplistener-based.html
http://blogs.msdn.com/b/jpsanders/archive/2009/09/29/walkthrough-using-httplistener-as-an-ssl-simple-server.aspx
http://technet.microsoft.com/en-us/library/cc725882(v=ws.10).aspx#BKMK_1

GUI Tools:
http://www.codeproject.com/Articles/437733/Demystify-http-sys-with-HttpSysManager
http://www.stevestechspot.com/ABetterHttpcfg.aspx
http://blog.pluralsight.com/2012/02/13/selfcert-create-a-self-signed-certificate-interactively-gui-or-programmatically-in-net/
http://makecertui.codeplex.com/
Marked as answer by Tratcher on 5/21/2014 at 2:13 PM
Mar 29, 2013 at 4:38 PM
Hi Chris,

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

Tugberk
Mar 31, 2013 at 10: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 10:02 AM
Hi,

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.
Coordinator
Apr 29, 2014 at 4:08 PM
Multiple urls can now be configured via the StartOptions.Urls collection:
http://msdn.microsoft.com/en-us/library/microsoft.owin.hosting.startoptions.urls(v=vs.113).aspx
http://msdn.microsoft.com/en-us/library/dn300219(v=vs.113).aspx

Here are some updated instructions for HTTPS hosting:
https://katanaproject.codeplex.com/wikipage?title=Selfhosting

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