What is the use of UseIISIntegration in C# Asp.net Core?

CsharpServer Side ProgrammingProgramming

All ASP.NET Core applications require a WebHost object that essentially serves as the application and web server. WebHostBuilder is used to configure and create the WebHost. You will normally see UseKestrel() and UseIISIntegration() in the WebHostBuilder setup code.

What do these do?

UseKestrel() − This registers the IServer interface for Kestrel as the server that will be used to host your application.

In the future, there could be other options, including WebListener which will be Windows only.

UseIISIntegration() − This tells ASP.NET that IIS will be working as a reverse proxy in front of Kestrel.

This then specifies some settings around which port Kestrel should listen on, forwarding headers, and other details.

Example

public class Program{
   public static void Main(string[] args){
      var host = new WebHostBuilder()
      .UseKestrel()
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseIISIntegration()
      .UseStartup()
      .Build();
      host.Run();
   }
}

Until ASP.NET Core 2.2, ASP.NET Core was hosted out-of-process in IIS,we had two processes for an application −

w3wp.exe, the IIS process

dotnet.exe, the ASP.NET Core process, where the Kestrel web server was started. This means that IIS and Kestrel were communicating between those two processes.

For this scenario, we use UseIISIntegration.

raja
Published on 25-Sep-2020 10:48:27
Advertisements