How to run multiple .NET Core APIs under one IIS Application?

Surya Sreepada
3 min readSep 11, 2020

--

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

  1. Visual Studio 2019 Community
  2. IIS
  3. Windows 10 Pro
  4. .NET Core 3.1
  5. ASP.NET Core Hosting Bundle

Project and Deployment Setup

Create two ASP.NET Core WebAPI Projects in same solution.

Project Structure

Add TestController.cs to have a [HttpGet] method for easy testing. Add similar TestController.cs in Second API

TestController.cs for sample API call

Changes in Startup.cs. Similar changes are added in SecondAPI Startup.cs

Startup.cs changes

Publish to Local Path with a specific Folder Structure

Publish Profile settings
Folder Structure for publishing the APIs under one Application (OneApp)

Application Pools and WebSite Settings

Application Pools
IIS Application 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/

Result

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.

--

--

Surya Sreepada

Surya is a Solutions Architect with 15 years of experience, primarily worked on Microsoft Technologies and AWS