Why are settings in web.config not inherited by child path applications?

Bob Rzadzki 16 Reputation points
2023-06-01T19:03:42.8933333+00:00

I have a folder, Container, with a web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <aspNetCore>
            <environmentVariables>
                <environmentVariable name="gut_check" value="all good" />
            </environmentVariables>
        </aspNetCore>
    </system.webServer>
</configuration>

and in Container/App, I have the published output of a .NET Core project with its own web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path=".">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\App.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

In the app, I retrieve the value of Configuration["gut_check"] and return it to the user. When I set this value on the command line, in the IDE's launch settings, or in App\web.config, this works as expected.

However, the setting in Container\web.config has no effect.

Expected result: Environment variables set in Container\web.config are inherited by the app in Container\App.

Is my expectation correct? Can I resolve this?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,609 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,371 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JasonPan - MSFT 4,806 Reputation points Microsoft Vendor
    2023-06-02T10:47:04.6966667+00:00

    Hi @Bob Rzadzki,

    After my testing, I found that the current requirement cannot be achieved.

    First of all, we cannot add a asp.net core virtual application under the main asp.net core application. Then the two apps are independent and won't share environmentVariables.

    If you want use environment variable globally, please check this official doc.

    Windows - Set environment variable globally


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Jason Pan

    0 comments No comments