This weekend ASP.NET Core RC2 was starting to show up! And it finally was released today. Get it fresh from here. We had here a long three days weekend with quite awful gray clouds and cold weather for the season, so a perfect excuse to get started!
The first project I wanted to port to ASP.NET Core RC2 is something I began to work on some time ago when Atlassian HipChat announced their new Connect framework!
I had it working with NancyFx; it is quite small and hacky at the moment, but at least an interesting little project to port on a weekend. The second part I wanted to have is to be able to make it run in a Docker container so that I will be able to deploy it on our Linux server at work.
So I installed the ASP.NET Core Tooling Preview for Visual Studio 2015 and created a new ASP.NET Core Web Application (.NET Core) in C#, for sure!
picked up Web API
Finally, I started the port which took me something like two to three hours!
I ended up with the following code for the Program.cs file. The interesting part is the UseUrls() which I didn’t have while trying to make it run with Docker, then it wasn’t bound to the right network, and the application wasn’t accessible outside of the Docker container.
Then I had some difficulties to have CORS working the way I wanted, but in fact, it ended up being an issue of returning JSON from my HipChat Connect GetGlance method. So it is quite easy to configure it in the Configure() method.
Next step was to port from NancyFx module to ASP.NET Core RC2 controller, which was quite natural with the Route, HttpGet, HttpPost, FromBody and FromQuery attributes. The main point of interest is the ValidateToken() method which validates a JWT token using a SymmetricSecurityKey, and that wasn’t straight!
To be able to test the HipChat Connect add-on, I needed to be able to expose my application from my local development machine to the internet so that I can add the add-on to one HipChat room and for that I used ngrok!
Using the same ngrok command I used for NancyFx with ASP.NET Core RC2 gave me as a result “Http Bad Request error while calling your end point!“
ngrok http -bind-tls=true 8080
To be able to make it work with ASP.NET Core RC2 I had to fine tune the command so that the host header is adapted, then it worked!
ngrok http -bind-tls=true -host-header=”localhost:52060” 52060
And to finish, I wanted to have the project running in a Docker container using Docker for Windows. To achieve that goal I used the following Dockerfile
Built the Docker image with
docker build -t hipchatconnect .
Then started the Docker container with
docker run -d -p 5000:5000 –name hipchatconnect hipchatconnect
Checked that I could access my first ASP.NET Core RC2 project running in Docker with the following url:
To expose the container using ngrok I had to use:
ngrok http -bind-tls=true -host-header=”docker:5000” docker:5000
After adding the add-on to one of our room, the final result is a HipChat Connect Glance showing the number of our TeamCity builds and their states.
As a conclusion, to that especially long post, I am so happy that I could finally play with the ASP.NET Core RC2 bits, run a little Web application on my Windows 10 machine but also in a Linux Docker container using Docker for Windows! I love those two technologies and see a bright future for both of them. I am also delighted that Microsoft made .NET Core an open source project.