0

错误信息

我一直在尝试设置 ASP.NET API,但在尝试检查连接字符串时,我一直在 IIS 服务器上收到此错误。该项目是一个直接的新 ASP.NET API 项目,仅在注册表中添加了 2 个变量。

我的连接字符串(web.config):

<configBuilders>
<builders>
<add name="Secrets" userSecretsId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxx" />
</builders>
</configBuilders>

<connectionStrings configBuilders="Secrets">
<add name="DefaultConnection" connectionString="Data Source=SERVER;Initial Catalog=myAPIApp;Persist Security Info=True;User ID=xxxxxxx;Password=xxxxxxx" />
</connectionStrings>
4

1 回答 1

0

安装以下Nuget软件包后,
https: //www.nuget.org/packages/Microsoft.Configuration.ConfigurationBuilders.Environment/ 在使用自定义配置生成器之前,
我们应该先注册。configbuilder

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection,
             System.Configuration, Version=4.0.0.0, Culture=neutral,
             PublicKeyToken=b03f5f7f11d50a3a"
             restartOnExternalChanges="false" requirePermission="false" />
  </configSections>

请参考我的优先获取ServiceIDfrom的配置。System Environment Variables

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection,
             System.Configuration, Version=4.0.0.0, Culture=neutral,
             PublicKeyToken=b03f5f7f11d50a3a"
             restartOnExternalChanges="false" requirePermission="false" />
  </configSections>

  <configBuilders>
    <builders>
      <add name="Secrets" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </builders>
  </configBuilders>

  <appSettings configBuilders="Secrets">
    <add key="ServiceID" value="ServiceID value from web.config" />
    <add key="ServiceKey" value="Spotify" />
  </appSettings>

  <connectionStrings configBuilders="Secrets">
    <add name="default" connectionString="Data Source=web.config/mydb.db" />
  </connectionStrings>

ServiceID/ServiceKey如果设置,将从系统环境变量中获取值。
如果问题仍然存在,请随时告诉我。

于 2020-06-18T07:42:33.487 回答