Asp.Net 部署到 IIS(本地)的核心应用无法从 "Secrets-Manager" 中读取值?
Asp.Net Core app deployed to IIS (locally) cannot read values from "Secrets-Manager"?
当我使用 dotnet publish -c Release
编译我的应用程序并将应用程序部署到 IIS 时,一切正常。当我尝试从 Secrets-Manager
检索值时出现问题。
我确保我在 IIS 上的应用程序以 "Development" 模式为目标,以确保我使用的是 "Secrets-Manager" 而不是 Azure Key Vault。
我在 Startup.cs 文件中添加了 Console.WriteLine
以确保我处于 Development
模式。
当我导航到我的站点上需要从 "Secrets-Manager" 检索 APIKey 和 APISecret 的位置时,它为空。
这是我在 Startup.cs
中的设置:
Console.WriteLine($"Enviornment is: {ContextBoundObject.HostingEnvironment.EnvironmentName}");
if (ContextBoundObject.HostingEnvironment.IsProduction())
{
var builtConfig = config.Build();
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback
)
);
config.AddAzureKeyVault(
$@"https://{builtConfig["KeyVaultName"]}.vault.azure.net/",
keyVaultClient,
new DefaultKeyVaultSecretManager()
);
然后我从 "Secrets-Manager" 检索秘密:
string apiKey = configuration[nameof(VaultKeys.CloudinaryApiKey)];
string apiSecret = configuration[nameof(VaultKeys.CloudinaryApiSecret)];
当我通过按 F5 运行 IISExpress 上的应用程序时,这一切都有效,但当我将它部署到本地 IIS 时,它不起作用。
这是预期的行为吗?
问题的解决方案是在 IIS 上本地部署时确保“secrets.json”文件与 asp.net 核心项目位于同一目录中。
当我使用 dotnet publish -c Release
编译我的应用程序并将应用程序部署到 IIS 时,一切正常。当我尝试从 Secrets-Manager
检索值时出现问题。
我确保我在 IIS 上的应用程序以 "Development" 模式为目标,以确保我使用的是 "Secrets-Manager" 而不是 Azure Key Vault。
我在 Startup.cs 文件中添加了 Console.WriteLine
以确保我处于 Development
模式。
当我导航到我的站点上需要从 "Secrets-Manager" 检索 APIKey 和 APISecret 的位置时,它为空。
这是我在 Startup.cs
中的设置:
Console.WriteLine($"Enviornment is: {ContextBoundObject.HostingEnvironment.EnvironmentName}");
if (ContextBoundObject.HostingEnvironment.IsProduction())
{
var builtConfig = config.Build();
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback
)
);
config.AddAzureKeyVault(
$@"https://{builtConfig["KeyVaultName"]}.vault.azure.net/",
keyVaultClient,
new DefaultKeyVaultSecretManager()
);
然后我从 "Secrets-Manager" 检索秘密:
string apiKey = configuration[nameof(VaultKeys.CloudinaryApiKey)];
string apiSecret = configuration[nameof(VaultKeys.CloudinaryApiSecret)];
当我通过按 F5 运行 IISExpress 上的应用程序时,这一切都有效,但当我将它部署到本地 IIS 时,它不起作用。
这是预期的行为吗?
问题的解决方案是在 IIS 上本地部署时确保“secrets.json”文件与 asp.net 核心项目位于同一目录中。