Q:

How to solve the HTTP Error 403.14 - Forbidden in Asp.Net Core API?

I am developing Asp.Net Core 3.1 API. Its running fine and I am deploying it on IIS and It's giving me the below error.

HTTP Error 403.14 - Forbidden

I have found out the root cause of the issue, I am putting my observation below.
This is my original web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\EngageAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

So when I run the project locally using the visual studio 2019, it is changing the content of web.config to the below mentioned.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="COMPLUS_ForceENC" value="1" />
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

So when I Publish the application in Release solution configuration, it generates the web.config with the latest changes. and when I deploy the API using this publish folder in IIS and run the application, it gives the 403.14 error.
To fix this I have manually copied the old web.config content to the IIS virtual directory web.config. and I am able to run the application successfully.
So learning from this is that We need to handle it differently if we are making any changes on the web.config, But I would suggest not making any changes in the web.config, instead use the appsettings.json for configuration.
So I have three questions here.

What is the root cause the issue, I have referred this question but didn't get any idea that why do we get this error?
How can we solve the issue in a cleaner and easy way?
if it is really necessary to modify the web.config, how can we do it in a clean way?

Update:
As suggested by @ScareCrow in his answer I have made the required changes and I have started getting the below error.

HTTP Error 500.0 - ANCM In-Process Handler Load Failure

Event Viewer logs:

Log Name:      Application Source:        IIS AspNetCore Module V2
Date:          7/15/2020 3:29:03 AM Event ID:      1031 Task Category:
None Level:         Error Keywords:      Classic User:          N/A
Computer:      SUSIAALGCBWSXT1.FCStone.com Description: Application
'D:\Octopus\Applications\Beta\ISOXMLValidationApi\1.0.0.9' failed to
start. Exception message: Executable was not found at
'D:\Octopus\Applications\Beta\ISOXMLValidationApi\1.0.0.9%LAUNCHER_PATH%.exe'
Event Xml: 

1031
2
0
0x80000000000000

1090650
Application
SUSIAALGCBWSXT1.FCStone.com
      
Application 'D:\Octopus\Applications\Beta\ISOXMLValidationApi\1.0.0.9' failed to
start. Exception message: Executable was not found at
'D:\Octopus\Applications\Beta\ISOXMLValidationApi\1.0.0.9%LAUNCHER_PATH%.exe'
Process Id: 19916.
File Version: 13.1.20142.5. Description: IIS ASP.NET Core Module V2. Commit: 844a82e37cae48af2ab2ee4f39b41283e6bb4f0e

A:

The issue is resolved by updating the Visual Studio to 16.6.4 version.

