获取大麻的Azure配置值
当我在本地运行代码并在Azure上运行时,将设置从Azure的配置中拉出时,我正在尝试拉动AppSetting.json设置(在Blazor Server应用中)。但是,即使它是实时的,我的代码也会从appsettings.json中提取。我为我的startup.cs文件提取这些值,如这样:
options.Authority = Configuration.GetValue<string>("AuthenticationServer:IDAuthority");
options.ClientId = Configuration.GetValue<string>("AuthenticationServer:IDClientID");
options.CallbackPath = Configuration.GetValue<string>("AuthenticationServer:IDRedirectURI");
在我的appsetting.json文件中,我的设置是这样存储的:
{
"AuthenticationServer": {
"IDAuthority": "Some Value",
"IDClientID": "Another Value",
"IDRedirectURI": "/Index/"
},
}
在azure app服务中,在设置 - &gt; configuration下,在“应用程序设置”选项卡中,我有三个密钥/价值对:
“ idauthority” - “新值”
“ idclientid” - “另一个新值”
“ idredirecturi” - “/index/”
但是当我这样做时,值仍然会从appsettings.json而不是azure中提取。我也尝试了:
“ authenticationserver_idauthority” - “新值”
“ authenticationserver_idclientid” - “另一个新值”
“ authenticationserver_idredirecturi” - “/index/”
并获得相同的结果。那么,我应该如何从Azure中汲取这些价值?
顺便说一句,获得这样的Azure DB连接字符串,可以正常工作:
services.AddDbContext<DBContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("ConnString")));
I am trying to pull appsetting.json settings (In Blazor Server app) when I run my code locally and have the settings be pulled from Azure's Configuration when it is running on Azure. But, my code will pull from appsettings.json even if it is live. I pull these values for my Startup.cs file, like this:
options.Authority = Configuration.GetValue<string>("AuthenticationServer:IDAuthority");
options.ClientId = Configuration.GetValue<string>("AuthenticationServer:IDClientID");
options.CallbackPath = Configuration.GetValue<string>("AuthenticationServer:IDRedirectURI");
In my appsetting.json file, I have the settings stored like this:
{
"AuthenticationServer": {
"IDAuthority": "Some Value",
"IDClientID": "Another Value",
"IDRedirectURI": "/Index/"
},
}
And in Azure App Service, under Settings->Configuration, in the Application Settings Tab, I have three key/value pairs:
"IDAuthority" - "New Value"
"IDClientID" - "Another New Value"
"IDRedirectURI" - "/Index/"
But when I do this, the values still get pulled from appsettings.json and not Azure. I've also tried:
"AuthenticationServer_IDAuthority" - "New Value"
"AuthenticationServer_IDClientID" - "Another New Value"
"AuthenticationServer_IDRedirectURI" - "/Index/"
And get the same results. So, how should I pull these values from Azure?
As an aside, getting the Azure db connection string like this, works fine:
services.AddDbContext<DBContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("ConnString")));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您只能在将代码发布到Azure之前更改。
首先,我们需要知道何时要读取存储在Azure应用程序配置中的值时,我们需要使您的应用程序连接到Azure应用程序配置,然后我们可以获得我们设置的内容,并且可以使用钥匙名获得值。并且opreation应该与从appsettings.json获取值相同,这是我的代码:
因此,我想您可以在要读取AppSettings.json中的appsettings.json中的代码连接到Azure App Configuration。在要发布到Azure之前,请删除代码。
I think you can only change the code before publish it to AZURE.
Firstly we need to know when we want to read the value stored in azure app configuration, we need to make your application connect to Azure app configuration and then we can get what we set, and we can get value with the key name. And the opreation should be the same as getting value from appsettings.json, here's my code:
So I think you may comment the code connect to Azure app configuration when you want to read configuration in appsettings.json, and un-comment the code before you want to publish to azure.
似乎是一个命名公约问题。因为我的值嵌套在我的appsettings.json文件中,所以我必须确保参数的深度包含在Azure设置中。
要获得值:
然后,我必须确保在Azure中的配置设置为“ Authenticationserver:Idauthority”
Seems to be a naming convention issue. Because my values were nested in my appsettings.json file, I had to make sure the depth of the parameter was included in the Azure setting.
To get the value:
and I then had to make sure the configuration setting, in Azure, was titled: "AuthenticationServer:IDAuthority"