6 different ways to run an asp.net core web application

<blink> Gratuitous self promotion: Joseph Cooney and I will be talking about running asp.net core on Linux, at the upcoming DDD Brisbane conference at 4:05 pm, 3rd of December, less than 3 weeks from now. </blink>

Now that you've suffered through the advertisement, here's some content.

PLEASE tell me if I say anything misleading in what follows... if I'm going to stand in front of people and pretend to be worth listening to, I want some rigorous vetting to occur first.

Tell me leon, what are all the ways you can run an asp.net core web site?

Well I don't know all the ways, but I do know 6 different ways!

Get your head around this lot (even if it requires extra background reading) and you'll understand a lot about how asp.net core sites work.

  1. Visual Studio F5

If you're developing an asp.net core website in Visual Studio, then you might run it by pressing F5, for debugging purposes. But that's not the only show in town...

  1. Commandline "dotnet run"

Your website is really a dotnet console app, that self-hosts a website using a tiny webserver called Kestrel. (There's a lot to unpack in that sentence, but just let it wash over you for now)

You can run it, from the console, by calling dotnet run from the folder that contains the project.json file.

The output in the console will say something like:

Now listening on: http://localhost:2000

So if you then browse to http://localhost:2000, you'll see your website (and the console will show logging info about your visit)

  1. dotnet publish → cd bin{...}\publish → dotnet YourProject.dll

On your local machine, you can prepare the application for deployment by running "dotnet publish". This builds the application artifacts, does any minification and so forth.

If you don't specify where the published results go they will end up in YourProject\bin\debug\netcoreapp1.0\publish

If you go into that folder you can run the resulting artifacts by calling:

dotnet YourProject.dll

Note that you don't call "dotnet run YourProject.dll" -- leave out the run for this one!

So the commands in full (starting in the folder that contains the project.json file)

dotnet publish
cd bin\debug\netcoreapp1.0\publish
dotnet YourProject.dll
  1. IIS

You can host it in IIS. I've never done this and don't intend to. Me and IIS are parting ways for now. But it can be run by IIS. More info here: Publishing to IIS and here: Publishing to IIS with Web Deploy using Visual Studio.

  1. Running on Linux, from the console.... "dotnet YourProject.dll"

You can grab the artifacts from your local computer's "publish" folder (created in step 3), and copy them onto a Linux machine (using a technique such as SSH, scp, sftp). Then you can run it in the console, exactly the same as step 3:

dotnet YourProject.dll

(This assumes that you have have .net core installed on that linux machine already, instructions here.)

From a different console attached to the same machine, you can view the website by running, for example:

curl http://localhost:2000

...which isn't the most comfortable way to surf the internet. But since our webapp isn't accessible from the open internet, it's about the best you can do at that point.

Also, as soon as that first console window is closed, the application will stop. So this is not your final production technique. For that....

  1. Running properly on linux, with supervisor + nginx

In Linux you can configure supervisor to run your application (and keep it running). This is analogous to the work that Application Pools do in Windows land.

And nginx is a popular webserver, analogous to using IIS on Windows. The two work together to run your application and deliver webrequests to it. You set up nginx to receive requests from the internet and pass them on to your application (i.e. to "proxy them" through to your application, also know as acting as a 'reverse-proxy')

Details about using supervisor, at TIL.secretGeek.net:

To learn how to configure nginx to proxy requests through to your application, try the article here:

With those in place, you can browse to your site from the internet (assuming you purchased a domain and configured it to point to the webserver, or perhaps you are browsing by IP address, like all hardcore nerds.)

Okay, that's 6 different ways to run your asp.net core web app.

(You can swap nginx for some other webserver like Apache, but I'm not counting that as a separate method, just a variation on number 6.)

(And you can user systemd and upstart instead of supervisor: notes here.)

What did I get wrong!?

Update: Some answers to this question have come in already...

I wrote Katana instead of Kestrel -- fixed.

You can of-course also host a .net core app inside an MS Word Macro.

I left out Azure. You can deploy .net core apps to Azure, and if that's something you're interested in doing, I think this article covers it nicely: Deploy ASP.NET Core 1.0 apps to Azure web apps.

Just kidding about the Word Macro.

Further reading

This document brings together documents on each deployment method: asp.net core: Publishing and Deployment.

 

My book "Choose Your First Product" is available now.

It gives you 4 easy steps to find and validate a humble product idea.

Learn more.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.