13

Actually I understand that IIS Express is lightweight development server. From the other side "dotnet run" runs the application as a console application and binds it to random port.

But what is the actual difference? I can launch big enterprise application by IIS Express and by "dotnet run" and both cases work perfectly.

Till now all the difference I see is that IIS Express adds icon to the taskbar and dotnet run allows to see console output. But those are minor differences. It should be some global ones why IIS Express is so widespread nowadays.

Some structurization can be found here: ASP.NET Core launch settings: IIS Express, IIS, Project, Executable. But it still doesn't explain the difference.

Alex Vovchuk
  • 2,828
  • 4
  • 19
  • 40
  • 1
    Initially you can follow my blog post to understand the differences, https://blog.lextudio.com/a-closer-look-at-asp-net-core-execution-model-b3c332f6ed1 But with in-process hosting (.NET Core 2.2), the situation is even more complex. No wonder it is hard to find the right materials. – Lex Li Feb 13 '20 at 02:36

1 Answers1

9

dotnet run will use the embedded Kestrel server. IIS Express will use IIS Express as a reverse proxy which calls Kestrel behind the scenes. In either case a server is hosting your app.

You can toggle your local server choice by adjusting the run configuration. IIS Express will use...IIS Express. But if you instead select the project (in the case of the screenshot, it's titled weatherapi) it will use Kestrel instead. You'll see a command prompt pop up, showing some basic configuration data (assuming you haven't changed the default logging output). The first time it's run, you may have to accept/install the localhost TLS certificate, so that you don't run into TLS errors.

enter image description here

One way of confirming which process you are using, is to call get-process in powershell, along with either iisexpress or {nameOfProject}

enter image description here

More info from the docs https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/?view=aspnetcore-3.1&tabs=windows

petah
  • 320
  • 3
  • 13
  • 5
    Could somebody explain to me, why would you use one over the other? – QmlnR2F5 Feb 25 '21 at 15:56
  • 1
    I have the same question as the comment above. I understand the need for IIS to reverse proxy to Kestrel in the production environment (Kestrel is missing lots of features), but why is IIS Express part of the mix in ASP.NET Core? It seems to add nothing over Kestrel. A single launch option would have been so much clearer. – Ben Mills May 06 '21 at 01:53
  • The existence of IIS / IIS Express predates Kestrel and .NET Core for many years. An good explanation as to why there are still two server layers can be found here: https://stackoverflow.com/a/46878663/1424754 – nicholas Sep 28 '21 at 17:32