繁体   English   中英

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

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

我正在测试 AS.NETCORE_ENVIRONMENT 生产/开发变量。

我将波纹管代码添加到 Properties/PublishProfiles/FolderProfile.pubxml

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

发布生成的精细 webconfig。 然后使用不带参数的命令运行 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\

但是带参数运行没问题

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\

为什么 web.config 中的 SSSS 值在没有参数的第一次尝试中被省略?

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM