How to run multiple .NET Core APIs under one IIS Application?
The Problem
In the regular model of deploying .NET Core applications in IIS, you might be deploying them as separate IIS Applications and having separate domain names (or Port numbers) for each of them.
But, is it possible to have a single IIS Application for a group of .NET Core APIs, so that they can share a single domain name (and a Port number) though the individual APIs are completely not related to each other?
Yes, it is possible and let us see how it can be achieved.
Here is the GitHub Repo for code enthusiasts.
https://github.com/suryasreepada/MultiAPIOneIISAppSample
Tools and Environment
- Visual Studio 2019 Community
- IIS
- Windows 10 Pro
- .NET Core 3.1
- ASP.NET Core Hosting Bundle
Project and Deployment Setup
Create two ASP.NET Core WebAPI Projects in same solution.
Add TestController.cs to have a [HttpGet] method for easy testing. Add similar TestController.cs in Second API
Changes in Startup.cs. Similar changes are added in SecondAPI Startup.cs
Publish to Local Path with a specific Folder Structure
Application Pools and WebSite Settings
OneApp is an IIS Application running on port 8080. All sub folders underneath OneApp must be converted to Applications and select appropriate Application Pool for each one of them.
Now browse below URLs and they must return valid response.
http://localhost:8080/api/firstapp/test/
http://localhost:8080/api/secondapp/test/
Conclusion
With these simple settings, any API deployed in the same IIS Application can have completely different behavior independent of each other.
Questions?
If we deploy one API, do we need to restart the whole IIS Application?
Not required. Just stop Application Pool before deployment and start it after deployment. Traffic on the other APIs will not get disturbed.
Please share your questions and comments.