Hosting your dotnetcore app with Kestrel

Kestrel is the built-in web server for Microsoft’s dotnetcore platform. I do not know the actual etymology of Kestrel, but it sounds like a planet or the name of some obscure band that played at Fitzgerald’s in 1997. My band never played Fitzgerald’s in the 90’s. We played the Firehouse Saloon and The Side Car Pub, but that was 2000. We had some pretty catchy tunes.

Anyway, I was working on a project that used a dotnetcore app with some node.js magic thrown in. At that point in time I was new to both dotnetcore and node.js and the only way I knew how to get the webapp to run was by launching the project in Visual Studio.

The thing is, I wasn’t developing the dotnetcore part of the project;. I was working on another service that talked to it. Constantly building and re-running the solution in Visual Studio got to be a little time consuming and I couldn’t just navigate to the “bin” directory and run an executable.

The dotnetcore solution was built off of a template that was using the generic IIS hosting configuration in the Program.cs file. This configuration actually does invoke Kestrel (as all dotnetcore apps do) but not directly. The default configuration requires IIS and I didn’t have IIS on my machine or on a VM. I thought about setting it up, but then I thought there had to be a better way.

My research led me to learn more about Kestrel and their awesome set opening for 30 Foot Fall at the Blue Iguana in 1996. Sorry, not that Kestrel…I meant to say that my research helped me learn more about the mysterious built-in web server.

In order to run a dotnetcore app locally without installing or configuring a traditional webserver you need add the 2 bolded lines to the BuildWebHost method in the Program.cs file as follows:

public static IWebHost BuildWebHost(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .UseStartup<Startup>()
 .UseKestrel()
 .UseUrls("http://*:70000")
 .Build();

After that you can publish the app in Visual Studio and the artifacts directly from a command prompt by navigating to the “…\bin\Release\netcoreapp2.0\” directory and executing dotnet command.

>dotnet .\(appname).dll

I hope you all find that useful. And for those of you who were trying to find a blog about the screamo pioneers Kestrel, I apologize.

Privacy Policy Made with in Texas.