gpt4 book ai didi

azure-web-app-service - 在 Azure 上的 ASP.NET 5 中访问连接字符串

转载 作者:行者123 更新时间:2023-12-04 07:09:40 25 4
gpt4 key购买 nike

在 ASP.NET 5 中,我们如何以编程方式访问 Azure Web 应用程序的连接字符串?我已经能够检索到 TEST_APP_SETTINGS 值,但不能检索到 TestConnString 值。

App Settings and Connection Strings

这是我尝试过的:

services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));

恐怕 AppSettings 不存在。我也这样做了,应用程序设置显示了,但连接字符串没有显示。

启动.cs

// Setup configuration sources.
Configuration = new Configuration()
.AddJsonFile("config.json")
.AddEnvironmentVariables();

// Allow access from *.cshtml
services.AddSingleton<Configuration>(provider =>
{
return Configuration as Configuration;
});

开发.cshtml

@inject Microsoft.Framework.ConfigurationModel.Configuration config;

<dl>
@foreach(var k in @config.GetSubKeys())
{
<dt>@k.Key</dt>
<dd>@config.Get(k.Key)</dd>
}
</dl>

最佳答案

连接字符串设置为环境变量。因此,首先你必须add the environment variable configuration source然后连接字符串将被命名为 Data:NAME:ConnectionString,其中 NAME 是门户中连接字符串的名称。

例如,如果您的连接字符串是“ServerConnection”,那么您可以使用 Data:ServerConnection:ConnectionString

访问它

Here是验证映射环境配置映射的测试,他们可能会更好地解释它。

关于azure-web-app-service - 在 Azure 上的 ASP.NET 5 中访问连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30315461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com