• Home
  • About
  • Contact
  • ado.net
  • angular
  • c#.net
  • design patterns
  • linq
  • mvc
  • .net core
    • .Net Core MVC
    • Blazor Tutorials
  • sql
  • web api
  • dotnet
    • SOLID Principles
    • Entity Framework
    • C#.NET Programs and Algorithms
  • Others
    • C# Interview Questions
    • SQL Server Questions
    • ASP.NET Questions
    • MVC Questions
    • Web API Questions
    • .Net Core Questions
    • Data Structures and Algorithms

Tuesday, August 18, 2020

ASP.NET Core InProcess Hosting

 Admin     August 18, 2020     .Net, .Net Core, Asp.Net, C#     No comments   

In this article, I am going to discuss the ASP.NET Core InProcess Hosting in detail. Please read our previous article before proceeding to this article where we discussed the ASP.NET Core Main method in detail. As part of this article, we are going to discuss the following pointers in detail.
  1. What are the Tasks performed by CreateDefaultBuilder() method?
  2. What is InProcess hosting in ASP.NET Core?
  3. How to host ASP.NET Core Application using InProcess hosting Model?
  4. How does the InProcess hosting work in ASP.NET Core?
We are going to work with the same application that we created in our previous article. As we already discussed when we create an ASP.NET Core web application, then the ASP.NET Core framework creates the following Program class with the Main method for us.
ASP.NET Core InProcess Hosting Main Method

When we execute an ASP.NET core application then the .NET runtime looks for the Main() method. The Main() method is the entry point for the .net core application to execute.

As you can see from the above image the Main() method of the Program class calls the static CreateWebHostBuilder() method. Then the CreateWebHostBuilder() method calls the static CreateDefaultBuilder() method of the WebHost class. The CreateDefaultBuilder() method sets the web host which will host our application with default preconfigured configurations.

What are the Tasks performed by CreateDefaultBuilder() method?
As part of setting the web host, the CreateDefaultBuilder() method does several things. Some of them are as follows
  1. Setting up the webserver (will discuss in this article)
  2. Loading the host and application configuration from various configuration sources (will discuss in our upcoming articles)
  3. Configuring logging (will discuss in our upcoming articles)
Let us discuss what exactly the CreateDefaultBuilder() method does to configure and set up the webserver. From a hosting point of view, an ASP.NET core Web application can be hosted in two ways i.e. InProcess hosting or OutOfProcess hosting.

Here in this article, we are going to discuss InProcess hosting and in a later article, we will discuss the OutOfProcess hosting.

How to Configure InProcess hosting in ASP.NET Core?
To configure the InProcess hosting for ASP.NET Core Web application there is only one simple setting, just add the element to the application project file with a value of InProcess as shown in the below image. To find the application project file, just right click on your application from the solution explorer and click on the “edit yourapplication.csproj” option.
ASP.NET Core InProcess Hosting Application Project File

When we create a new ASP.NET Core Web application by using any template, by default the project file is created with InProcess hosting which is used for hosting the application in IIS or IIS Express scenarios.

In case of InProcess hosting (i.e. when the CreateDefaultBuilder() sees the value as InProcess for the AspNetCoreHostingModel element in the project file), behind the scene the CreateDefaultBuilder() method internally calls the UseIIS() method. Then host the application inside the IIS worker process (i.e. w3wp.exe for IIS and iisexpress.exe for IISExpress).

From the performance point of view, the InProcess hosting model delivers significantly higher request throughput than the OutOfProcess hosting model. Why we will discuss this at the end of this article.

The process name that will be used to execute the application is w3wp in the case of IIS. Similarly, if it is IIS Express then the process name will be iisexpress.

Let’s Confirm this:
Now if you will run the application, then you see the following hello world message in the browser.
ASP.NET Core InProcess Hosting

You are getting the above message from the following Startup class
ASP.NET Core InProcess Hosting Startup Class

To display the process name in the browser you need to use the System.Diagnostics.Process.GetCurrentProcess().ProcessName within the Startup as shown below.
ASP.NET Core InProcess Hosting Startup Class to display Hosting Name

Now when we run the application from visual studio it displays the message in the browser as shown below.
ASP.NET Core InProcess Hosting displaying Hosting Name

This is because by default the Visual Studio uses IISExpress when we run an application as shown in the below image.
ASP.NET Core InProcess Hosting IIS Express in Visual Studio

The IIS Express is a lightweight, self-contained version of IIS. It is optimized for web application development. The most important point is that we use it only in development, not for production. In production we generally use IIS. In a later article, we will discuss how to deploy an ASP.NET Core application on IIS.

The OutOfProcess hosting
In the case of OutOfProcess hosting, there are 2 web servers
  1. An internal web server and
  2. One external web server.
The internal web server is called as Kestrel and the external web server can be IIS, Nginx or Apache.

With the InProcess hosting model, there is only one web server i.e. the IIS. So, in the case of the InProcess hosting model, we do not have the performance penalty for navigating the requests between the internal and external web servers. This is the reason why the InProcess hosting model delivers significantly higher request throughput than the OutOfProcess hosting model.
ASP.NET Core InProcess Hosting

In the next article, we will discuss the Kestrel Web Server in ASP.NET Core application in detail. Here, in this article, I try to explain the ASP.NET Core InProcess Hosting in detail. I hope this article will help you to understand the ASP.NET Core InProcess Hosting.

Summary:
I hope this post will be helpful to understand the concept of the ASP.NET Core InProcess Hosting
Please share this post with your friends and colleagues.
For any queries please post a comment below.
Happy Coding 😉
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post

0 comments:

Post a Comment

If you like this website, please share with your friends on Facebook, Twitter, LinkedIn.

Join us on Telegram

Loved Our Blog Posts? Subscribe To Get Updates Directly To Your Inbox

Like us on Facebook

Popular Posts

  • What is Dependency Injection(DI)
    Hi friends! Today we are going to learn about Dependency Injection and in our last session we have come across Static classes and where it s...
  • C# Programming Examples on Sorting
    Today i am going to tell you some of the Sorting programming questions in C#. Q1- Write a C# program to perform Selection sort. Ans:  Sel...
  • Calling Web API Service in a Cross-Domain Using jQuery AJAX
    In this article, I am going to discuss Calling Web API Service in a Cross-Domain Using jQuery AJAX . Please read our previous article befor...
  • ViewBag in ASP.NET Core MVC
    In this article, I am going to discuss the use of ViewBag in ASP.NET Core MVC application with examples. Please read our previous article ...
  • Recursion And Back Tracking
    In this article, I am going to discuss Recursion And BackTracking in detail. Please read our previous article where we discussed Master Th...
  • What is Abstract Class and When we should use Abstract Class
    Hi friends! In our previous sessions we have seen  Difference Between Class and Struct . And in our last session  we learnt Usability of Sec...
  • Binary to Decimal Conversion in C# with Examples
    In this article, I am going to discuss the Binary to Decimal Conversion in C# with some examples. Please read our previous article where w...

Blog Archive

Contact Form

Name

Email *

Message *

Tags

.Net .Net Core .Net Core MVC Algorithm Angular Anonymous Types Asp.Net Asp.Net MVC Blazor C# Data Structure Database Design Patterns Entity Framework Entity Framework Core Filters Interview Question Management Studio Programming Programs SQL Server SSMS Web API

Copyright © C# Techtics | All Right Reserved.

Protected by Copyscape