Home > Mobile >  Why Webservice doesn't use variable ASPNETCORE_ENVIRONMENT from web.config
Why Webservice doesn't use variable ASPNETCORE_ENVIRONMENT from web.config

Time:12-08

I am testing ASPNETCORE_ENVIRONMENT Production/Development variables.

I added bellow code to Properties/PublishProfiles/FolderProfile.pubxml

<Project>
  <PropertyGroup>
...
    <EnvironmentName>SSSS</EnvironmentName>
  </PropertyGroup>
</Project>

Publish generated fine webconfig. Then run webservice using command without parameters and bellow you can see the result Hosting environment: Production

C:\Users\xyz\Desktop\test>more 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=".\WebService.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="SSSS" />
        </environmentVariables>
      </aspNetCore>
      <modules runAllManagedModulesForAllRequests="false">
        <remove name="WebDAVModule"/>
      </modules>
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 2aceeb9d-68a1-49e6-a703-26f2e3099f59-->

C:\Users\xyz\Desktop\test>WebService.exe
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\xyz\Desktop\test\

But running with parameter is fine

C:\Users\xyz\Desktop\test>WebService.exe --environment ABC
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: ABC
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\Users\xyz\Desktop\test\

Why SSSS value from web.config is ommited in first try without parameters?

CodePudding user response:

The web.config is a file that is read by IIS and the ASP.NET Core Module to configure an app hosted with IIS. For self hosted services this file is not read by default and the base option is sending the parameter manually at command line.

  • Related