使用 Azure.Identity 進行驗證,並從 Service 連線 or 新增的環境變數取得 Azure 應用程式組態 端點。 使用下列程式代碼時,請取消批註您想要使用的驗證類型代碼段部分。
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var client = new ConfigurationClient(new Uri(endpoint), credential);
使用 azure-identity 進行驗證,並從 Service 連線 or 新增的環境變數取得 Azure 應用程式組態 端點。 使用下列程式代碼時,請取消批註您想要使用的驗證類型代碼段部分。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .clientSecret(System.getenv("AZURE_APPCONFIGURATION_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_APPCONFIGURATION_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
使用 Azure.Identity 進行驗證,並從 Service 連線 or 所新增的環境變數取得 Azure 應用程式組態 端點。 使用下列程式代碼時,請取消批註您想要使用的驗證類型代碼段部分。
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var client = new ConfigurationClient(new Uri(endpoint), credential);
使用 進行azure-identity驗證,並從 Service 連線 or 新增的環境變數取得 Azure 應用程式組態 端點。 使用下列程式代碼時,請取消批註您想要使用的驗證類型代碼段部分。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .clientSecret(System.getenv("AZURE_APPCONFIGURATION_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_APPCONFIGURATION_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
var connectionString = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CONNECTIONSTRING");
var builder = new ConfigurationBuilder();
builder.AddAzureAppConfiguration(connectionString);
var config = builder.Build();
使用 Azure.Identity 進行驗證,並從 Service 連線 or 新增的環境變數取得 Azure 應用程式組態 端點。 使用下列程式代碼時,請取消批註您想要使用的驗證類型代碼段部分。
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_ENDPOINT");
// Uncomment the following lines corresponding to the authentication type you want to use.
// system-assigned managed identity
// var credential = new DefaultAzureCredential();
// user-assigned managed identity
// var credential = new DefaultAzureCredential(
// new DefaultAzureCredentialOptions
// {
// ManagedIdentityClientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// });
// service principal
// var tenantId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_TENANTID");
// var clientId = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTID");
// var clientSecret = Environment.GetEnvironmentVariable("AZURE_APPCONFIGURATION_CLIENTSECRET");
// var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var client = new ConfigurationClient(new Uri(endpoint), credential);
使用 進行azure-identity驗證,並從 Service 連線 or 新增的環境變數取得 Azure 應用程式組態 端點。 使用下列程式代碼時,請取消批註您想要使用的驗證類型代碼段部分。
// Uncomment the following lines corresponding to the authentication type you want to use.
// for system-managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder().build();
// for user-assigned managed identity
// DefaultAzureCredential defaultCredential = new DefaultAzureCredentialBuilder()
// .managedIdentityClientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .build();
// for service principal
// ClientSecretCredential defaultCredential = new ClientSecretCredentialBuilder()
// .clientId(System.getenv("AZURE_APPCONFIGURATION_CLIENTID"))
// .clientSecret(System.getenv("AZURE_APPCONFIGURATION_CLIENTSECRET"))
// .tenantId(System.getenv("AZURE_APPCONFIGURATION_TENANTID"))
// .build();
String endpoint = System.getenv("AZURE_APPCONFIGURATION_ENDPOINT");
ConfigurationClient configurationClient = new ConfigurationClientBuilder()
.credential(credential)
.endpoint(endpoint)
.buildClient();