5

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.

  1. 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?
  2. How can we solve the issue in a cleaner and easy way?
  3. 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

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • 1
    I don't know if it is still actual with net core, but within .net framework this error used to be due to a lack of permission for the IIS user – Krusty Jul 10 '20 at 16:28
  • @Krusty thank you, but it's working with the original web.config content, so I think it's not related to permission – Vivek Nuna Jul 10 '20 at 16:33
  • What requests give you 403.14? When you write a web API, you should know what URLs can be handled by it (obviously not all URLs can yield 200). – Lex Li Jul 11 '20 at 04:35
  • @LexLi yes, It gives 403.14 – Vivek Nuna Jul 11 '20 at 04:38
  • @viveknuna which iis feature did you enabled? make sure you have enough permission assign to the publish folder. how you publishing site in iis?make sure your iis site pointing right published folder. – Jalpa Panchal Jul 13 '20 at 09:01
  • @JalpaPanchal as I mentioned in the question, Its working as expected if I change the web.config. so it is 100% not related to permission – Vivek Nuna Jul 13 '20 at 10:02
  • @viveknuna did you check iis is pointing the right publish folder? try to set `true` – Jalpa Panchal Jul 14 '20 at 09:32
  • @JalpaPanchal what if I need to make changes to web.config? – Vivek Nuna Jul 14 '20 at 09:51
  • @viveknuna https://github.com/dotnet/sdk/issues/7864 and https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.0#application-configuration – Jalpa Panchal Jul 17 '20 at 09:56
  • This issue used to happen with me,...maybe some patch was missing in IIS.. what got me out it was removing the V2 in web.config AspNetCoreModuleV2 to **AspNetCoreModule** – Rohit Kumar Jul 19 '20 at 17:02
  • @viveknuna From your error message, you haven't setup your default page properly, please try to check this tutorial https://windowswebhostingreview.com/troubleshoot-403-error-when-publishing-asp-net-core/. Hope it helps! – Mark Spencer Jul 20 '20 at 07:42

2 Answers2

1

Maybe the issue is related to the "ASPNETCORE_ENVIRONMENT" variable setup. We have to provide this information in IIS.

You can actually set it on the website in IIS.

  • Open the "Internet Information Services (IIS) Manager.

  • Go to the Website where you want to set the environment variable. Find the "Configuration Editor".

  • In the "Section" part of Configuration Editor, select system.webServer/aspNetCore in the left dropdown select ApplicationHost.config.

  • Click on environmentVariables then you will get the Current env variable. Add a new env variable.

  • name will be ASPNETCORE_ENVIRONMENT and value will be Development[staging/Prod].

  • Close the window and restart the website.

Give a try with the above. Happy Coding!!

ScareCrow
  • 497
  • 3
  • 6
  • 1
    Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/217942/discussion-on-answer-by-scarecrow-how-to-solve-the-http-error-403-14-forbidden). – Samuel Liew Jul 16 '20 at 05:58
0

%Launcher_PATH% and %LAUNCHER_ARGS% must be replaced during publish process.

<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">

Please have a look to this answer for more details

N1gthm4r3
  • 755
  • 1
  • 11
  • 23