.net core IIS 配置环境变量

当在本地开发时可以在launchSettings文件中配置环境变量如下:

  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "index.html",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "ancmHostingModel": "OutOfProcess"
    },
    "Web.WebApi": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "index.html",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
"Development"就是变量值,但是当项目发布出来后launchSettings是没有的,那么到哪里配置环境变量?
答案就是web.config文件,发布后会生成web.config文件,变量就是在里面设置,如下:
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Web.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
            <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development"/>
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

 

posted @ 2022-07-12 15:14  四夕木  阅读(659)  评论(0)    收藏  举报