ASP.NET Core

OutProcess Hosting Model ASP.NET Core

OutProcess Hosting Model ASP.NET Core

OutProcess Hosting Model ASP.NET Core

In ASP.NET Core, hosting refers to the process of running your web application and making it accessible over the internet or intranet. OutOfProcess hosting is one of the hosting options available in ASP.NET Core, which involves running your application in a separate process from the web server.

In the OutOfProcess hosting model, the web server (like IIS or Nginx) communicates with your ASP.NET Core application through a network protocol, usually HTTP. The web server acts as a reverse proxy, forwarding incoming HTTP requests to the ASP.NET Core application process, which then processes the requests and sends back responses to the web server, which in turn forwards them to the client.



In the case of the ASP.NET Core OutOfProcess Hosting Model, there are 2 web servers: -
1. An Internal Web Server, which is the Kestrel Web Server
2. An External Web Server can be IIS, Apache, or Nginx.


Depending on how you are running your application with the OutOfProcess hosting model, the external web server (i.e., IIS, Apache, and Nginx) may or may not be used.  

Method 1: Kestrel as Internet-Facing Web Server or External Web Server
We can use the Kestrel Web Server as the Internet-Facing web server, which will directly process the incoming HTTP requests.
In this scenario, only the Kestrel Server is used, and the other one, i.e., external web server (i.e., IIS, Apache, and Nginx), is not going to be used.
when we run the application using the .NET core CLI, Kestrel is the only Web Server that will be used to handle and process the incoming HTTP request,

Lets run our application in Command prompt by running dotnet run command and press the enter key
Now open the browser and navigate to any of the URL showing in command prompt after running above command



Method2: Kestrel as the Internal Web Server
The Kestrel can be used as the Internal Web Server i.e. the Kestrel Web Server can also be used along with a Reverse Proxy Server such as IIS, Apache, or Nginx

Why do we need a Reverse Proxy Server, If Kestrel can be used as a Web Server that can directly handle and process the incoming HTTP Request?
This is because the Reverse Proxy Server provides an additional layer of configuration and security which is not available with the Kestrel Server. It also maintains load balancing.
So, when we use Kestrel Web Server along with a Reverse Proxy Server, the Reverse Proxy Server will receive the incoming HTTP requests from the client and then forward that request to the Kestrel Web Server for processing. Once the Kestrel Server receives the request, it will process the request, generate the response, and send the response back to the Reverse Proxy Server, which then sends the response back to the requested client over the Internet who initially made the request.

Deploying an ASP.NET Core application to IIS and using IIS as a Reverse Proxy Server.
Now, the IIS Express receives the incoming HTTP request and then forwards the request to the Kestrel Web Server for processing. The Kestrel Web Server processes the request, generates the response, and sends the response back to the IIS Express, which in turn sends the response back to the client, i.e., to the browser.

With Out Of Process Hosting Model in Place, if we run the application using IIS Express Profile, then IIS Express Server will act as the External Web Server, and Kestrel act as the Internal Web Server.

With Out Of Process Hosting Model in Place, if we run the application using the WebApplication3 profile, then Kestrel is the only server that will host the application and Handle the Incoming HTTP Requests.





Benefits of OutOfProcess Hosting:
Isolation: Since the ASP.NET Core application runs in a separate process from the web server, it provides strong isolation. This isolation can be particularly useful for security, stability, and management purposes.
Runtime Independence: You can choose a different runtime (like .NET Core or .NET 6) for your ASP.NET Core application than the web server uses, allowing for version and framework flexibility.
Scalability: The application can be scaled independently of the web server. Multiple instances of the application can run and be load-balanced to handle high traffic.
Multi-Platform: OutOfProcess hosting is platform-agnostic, meaning you can host your ASP.NET Core application on various web servers and operating systems.
Upgrade Flexibility: You can upgrade the ASP.NET Core application independently of the web server, which can help in adopting new features, bug fixes, or even completely new versions of the framework.
Crash Isolation: If your ASP.NET Core application crashes, it doesn’t affect the web server or other applications running on the server.










Related Post

About Us

Community of IT Professionals

A Complete IT knowledgebase for any kind of Software Language, Development, Programming, Coding, Designing, Networking, Hardware and Digital Marketing.

Instagram