IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process

Introduction

 
I am here to introduce you to InProcess hosting in a .Net Core MVC 3.1 web application with the w3wp worker process.
 
Also, we will learn how to configure the source code to the IIS and run the application with debugging.
 
I suppose that since you are looking for hosting, you have already installed the necessary features for that.
 
The main feature you need to install for hosting in IIS is the IIS runtime support (ASP.NET Core Module v2) Hosting Bundle.
 
I have a Visual studio 2019 community version with pre-installed features for the development of an application.
 
Let begin with downloading the ASP.NET Core Runtime Hosting bundle from Url https://dotnet.microsoft.com/download/dotnet-core/3.1 
 
Step 1
 
If you haven't already installed the Hosting Bundle, please install it from the given link.
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
Step 2
 
After installing, let's go to the IIS manager and map our Project directory source in IIS. 
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
Step 3
 
Map your Source Code path.
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
Step 4
 
I have set the Application Pool setting with NetworkServices Identity. You can also choose another as per your requirement.
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
Step 5
 
Add the Module AspNetCoreModuleV2 by following the below-given process in the screenshot.
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
You can also do this at the application level in your project's web.config
 
If you don't have web config right now, please follow step 6 given below and build your project. 
  1. <system.webServer>  
  2.    <modules>   
  3.      <add name="AspNetCoreModuleV2" />  
  4.    </modules>  
  5.  </system.webServer>  
Step 6
 
Add the Marked Code in your Launchsettings.json 
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
Add the below code marked in bold:
  1. {  
  2.   "iisSettings": {  
  3.     "windowsAuthentication"false,  
  4.     "anonymousAuthentication"true,  
  5.     "iis": {  
  6.       "applicationUrl""http://localhost:1111/",  
  7.       "sslPort": 0  
  8.     },  
  9.     "iisExpress": {  
  10.       "applicationUrl""http://localhost:59631",  
  11.       "sslPort": 44338  
  12.     }  
  13.   },  
  14.   "profiles": {  
  15.     "IIS Express": {  
  16.       "commandName""IISExpress",  
  17.       "launchBrowser"true,  
  18.       "environmentVariables": {  
  19.         "ASPNETCORE_ENVIRONMENT""Development",  
  20.         "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES""Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"  
  21.       }  
  22.     },  
  23.     "TestDemo": {  
  24.       "commandName""Project",  
  25.       "launchBrowser"true,  
  26.       "environmentVariables": {  
  27.         "ASPNETCORE_ENVIRONMENT""Development",  
  28.         "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES""Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"  
  29.       },  
  30.       "applicationUrl""https://localhost:5001;http://localhost:5000"  
  31.     },  
  32.     "Local IIS": {  
  33.       "commandName""IIS",  
  34.       "launchBrowser"true,  
  35.       "launchUrl""http://localhost:1111/",  
  36.       "environmentVariables": {  
  37.         "ASPNETCORE_ENVIRONMENT""Development"  
  38.       }  
  39.     }  
  40.   }  
  41. }  
Step 6
 
Please make sure your project is running with InProcess hosting Model
 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
  1. <PropertyGroup>  
  2.    <TargetFramework>netcoreapp3.1</TargetFramework>    
  3.    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>  
  4.  </PropertyGroup>  
Step 7 
 
As you have recently created a profile using launchsetting.json, now you can change the Debug property to Local IIS and run your application.

 

IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process

 

 
IIS Hosting .Net Core MVC 3.1 | In Process Hosting | w3wp.exe Worker Process
 
Here you can see the URL. Our mapping URL http://Localhost:1111 is working now and you can debug your code.
 
If you are still facing issues with reaching breakpoints, please add webBuilder.UseIIS(); to your program.cs.
  
  1. public static IHostBuilder CreateHostBuilder(string[] args) =>  
  2.           Host.CreateDefaultBuilder(args)  
  3.               .ConfigureWebHostDefaults(webBuilder =>  
  4.               {  
  5.                   webBuilder.UseIIS();  
  6.                   webBuilder.UseStartup<Startup>();  
  7.               });  
  8.   }  
That's it

Summary

 
In this article, we have learned about hosting a .NET Core MVC 3.1 web application to IIS without kestrel using the w3wp worker process. 
 
Hope it helps.
 
Also, if you have any suggestions regarding hosting in IIS, please comment below.