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

3

7

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

Impermissible answered 10/7, 2020 at 15:49 Comment(11)
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 userTodd
@Todd thank you, but it's working with the original web.config content, so I think it's not related to permissionImpermissible
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).Fiore
@LexLi yes, It gives 403.14Impermissible
@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.Glucose
@JalpaPanchal as I mentioned in the question, Its working as expected if I change the web.config. so it is 100% not related to permissionImpermissible
@viveknuna did you check iis is pointing the right publish folder? try to set <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>Glucose
@JalpaPanchal what if I need to make changes to web.config?Impermissible
@viveknuna github.com/dotnet/sdk/issues/7864 and learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/…Glucose
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 AspNetCoreModuleMistake
@viveknuna From your error message, you haven't setup your default page properly, please try to check this tutorial windowswebhostingreview.com/…. Hope it helps!Bethlehem
L
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!!

Lichfield answered 14/7, 2020 at 15:33 Comment(1)
Comments are not for extended discussion; this conversation has been moved to chat.Jaw
C
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

Chromaticity answered 20/7, 2020 at 6:18 Comment(2)
I am not looking for thisImpermissible
your error message says -> Exception message: Executable was not found at 'D:\Octopus\Applications\Beta\ISOXMLValidationApi\1.0.0.9%LAUNCHER_PATH%.exe'Chromaticity
P
0

Rather than set the environment variable in IIS settings, you can modify your project file so that the setting is included in the published web.config automatically:

<!-- Custom property group added to add the environment name during publish -->
<!-- The EnvironmentName property is used during the publish for the environment variable in web.config -->
<PropertyGroup Condition="'$(Configuration)' == '' Or '$(Configuration)' == 'Debug'">
    <EnvironmentName>Development</EnvironmentName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' != '' AND '$(Configuration)' != 'Debug'">
    <EnvironmentName>Production</EnvironmentName>
</PropertyGroup>
Pinxit answered 15/6 at 19:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.