-1

For different deployment environments, we want to either publish our application via IIS, or via Windows Service.

From this thread we learned that we have to remove the other UseABC() option from Program.cs -> CreateHostBuilder() -> ConfigureWebHostDefaults().

Just to be clear: either UseIIS() or UseKestrel() should be enabled there (in fact, last one wins, but this is not the point).

Is this it?

Is there no better option than to create two different deployment packages?

Ideally, there would be one set of binaries that supports both, IIS and Windows Service as hosting environment. Any ideas?

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Nicolas
  • 754
  • 8
  • 22
  • 1
    Why? You need 2 different packages and 2 different source codes for Kestrel vs IIS (for example, Kestrel doesn't use a web.config, while it is required for IIS, and as you saw you need different middleware depending on the server to be used). You should also really consider this approach, you can find different behaviours depending on the server which will make debugging errors much more complicated – Camilo Terevinto Oct 13 '21 at 13:56
  • The `web.config` file is automatically created for the kestrel deployment also. I didn' try to remove it, but it doesn't hurt also. So the only change in code is this one line that selects the target environment. If there is no other way than to toggle this line - ok. But other than that - currently - there is no need to change anything else... – Nicolas Oct 13 '21 at 14:01
  • I've never done this, but perhaps this helps? https://stackoverflow.com/questions/42272021/check-if-asp-netcore-application-is-hosted-in-iis - I've been lucky enough to almost never have to worry about IIS since I started working on ASP.NET Core back in 2016 :) – Camilo Terevinto Oct 13 '21 at 14:05
  • @CamiloTerevinto thanks for the link; but the information there is outdated, as previously when hosted in IIS, there also was Kestrel used internally - it was called `UseIISIntegration()` therefore. This changed now since net core 3.? – Nicolas Oct 13 '21 at 14:16
  • I'd suggest you to try it in a new app, as I don't see how the most voted answer could have changed between versions honestly. IIS most likely still set those environment variables when it starts the application. – Camilo Terevinto Oct 13 '21 at 14:21
  • Sorry for being misleading, I don't doubt these variables. But this is not my point. The difference now is that `UseIISIntegration()` does not work anymore, as this means that kestrels hosts the application and interacts with IIS. This no longer is the case - now IIS directly hosts the application and for this `UseIIS()` is needed - but this conflicts with `UseKestrel()` ;-) – Nicolas Oct 13 '21 at 14:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/238103/discussion-between-camilo-terevinto-and-nicolas). – Camilo Terevinto Oct 13 '21 at 14:34

1 Answers1

0

Using .ConfigureKestrel() instead of UseKestrel() solved the issue!

Reference: https://stackoverflow.com/a/63505860/2477582

Nicolas
  • 754
  • 8
  • 22