Start learning free

LESSON 149 OF 173 · BACKEND: SHIPPING IT

A Real Web Server: Kestrel

Practice

So far the shop ran with dotnet run, or the course ran it for you. dotnet run compiles the shop again at every start: handy while you change code, wasteful on a server. On a server, dotnet publish -o out compiles the shop once, into out/shop.dll, and the command dotnet out/shop.dll runs it.

Who answers the requests? In ASP.NET Core the web server is built in: app.Run() starts Kestrel, a web server made for real traffic. It answers many requests at the same time and, for each one, calls your app's routes. There are no workers to set.

The command line is the program's name, dotnet, then the compiled app, then the app's options: the words after the .dll go to CreateBuilder(args). For example, a blog project, blog.csproj, published with -o out, could start with:

dotnet out/blog.dll --environment Staging

One option matters for the shop. --urls sets the address and the port: without it, the shop listens on http://localhost:5000, which only programs on the server itself can reach, while 0.0.0.0 means every network interface. With the full command, the check prints:

$ dotnet out/shop.dll --urls http://0.0.0.0:8000
dotnet: runs the compiled shop, and app.Run() starts Kestrel, the web server inside ASP.NET Core, made for real traffic
out/shop.dll: the shop, compiled by dotnet publish -o out; the words after it go to CreateBuilder(args)
--urls http://0.0.0.0:8000: listens on port 8000 of every network interface, so other machines can connect
Kestrel answers many requests at the same time (no workers to set), and for each one it calls your app's routes:
GET / -> 200 OK: The shop is open

Your task: the shop's app is already written. Fill the list command, one string per part: "dotnet", then the compiled shop "out/shop.dll", then "--urls http://0.0.0.0:8000".


Assignment
Follow the Coding Tutorial to write the command line that runs the compiled shop on the server.


Hint
The app's options come after the .dll. The compiled shop is the folder from -o, a slash, and the project's name with .dll.


STEP 1 OF 3
    Ctrl + Enter to check