简体   繁体   English

为什么 Webservice 不使用来自 web.config 的变量 AS.NETCORE_ENVIRONMENT

[英]Why Webservice doesn't use variable ASPNETCORE_ENVIRONMENT from web.config

I am testing AS.NETCORE_ENVIRONMENT Production/Development variables.我正在测试 AS.NETCORE_ENVIRONMENT 生产/开发变量。

I added bellow code to Properties/PublishProfiles/FolderProfile.pubxml我将波纹管代码添加到 Properties/PublishProfiles/FolderProfile.pubxml

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

Publish generated fine webconfig.发布生成的精细 webconfig。 Then run webservice using command without parameters and bellow you can see the result Hosting environment: Production然后使用不带参数的命令运行 webservice,您可以在下面看到结果 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?为什么 web.config 中的 SSSS 值在没有参数的第一次尝试中被省略?

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. web.config 是由 IIS 和 ASP.NET 核心模块读取的文件,用于配置由 IIS 托管的应用程序。对于自托管服务,默认情况下不读取此文件,基本选项是在命令行手动发送参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebService 不读取 web.config - WebService doesn't read web.config ef core 在更新数据库期间不使用 AS.NETCORE_ENVIRONMENT - ef core doesn't use ASPNETCORE_ENVIRONMENT during update-database 如何在运行时设置 ASPNETCORE_ENVIRONMENT 变量 - How to set ASPNETCORE_ENVIRONMENT variable at runtime 是否可以重命名 ASPNETCORE_ENVIRONMENT 变量? - Is it possible to rename ASPNETCORE_ENVIRONMENT variable? 在T4模板中获取ASPNETCORE_ENVIRONMENT? - Get ASPNETCORE_ENVIRONMENT in T4 Template? 为什么在Azure上设置ASPNETCORE_ENVIRONMENT变量时需要发布我的project.json - Why do I need to publish my project.json when setting ASPNETCORE_ENVIRONMENT variable on Azure 为什么存在 aspNetCore web.config 部分时,launchSettings.json 配置文件中的 environmentVariables 不加载? - Why do environmentVariables from launchSettings.json profiles not load when aspNetCore web.config sections exist? ".NET Core 控制台应用程序和 aspnetcore_environment 变量" - .NET Core console app and aspnetcore_environment variable 为什么 ChartJs.Blazor 有错误(更改 ASPNETCORE_ENVIRONMENT) - Why is there an error in ChartJs.Blazor (change in ASPNETCORE_ENVIRONMENT) smtpClient不读取Web.config - smtpClient doesn't read the Web.config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM