读取应用程序服务的配置部分

发布于 2025-01-14 08:27:39 字数 1096 浏览 5 评论 0 原文

我们很难从代码中读取 Azure 应用服务的配置部分。我们有一个特定的需要,从应用服务自己的配置部分读取一个标志。我已将 Azure 门户中的新属性添加到应用服务的配置部分。我正在关注 https://learn.microsoft.com/ en-us/azure/app-service/configure-common?tabs=portal

https: //learn.microsoft.com/en-us/azure/app-service/configure-language-dotnetcore?pivots=platform-windows#access-environment-variables

读取变量作为环境变量但没有运气。

我还想提一下,我们正在尝试从 .NET Core 3.1 应用程序读取配置变量,我已经实现了以下三种不同的方法来读取变量,但均不成功:

var authType = configuration["AUTHTYPE"];

var authType2 = configuration.GetValue("AUTHTYPE");

var authType3 = Environment.GetEnvironmentVariable("AUTHTYPE");

AUTHTYPE 是应用服务本地配置部分中的配置名称。我尝试将此配置读取为“AUTHTYPE”、“ASPNETCORE_AUTHTYPE”和“APPSETTING_AUTHTYPE”,但都无法检索该值。

请帮助我们了解如何访问这些变量,因为这个问题目前阻碍了我们。 如果您需要更多信息或详细信息,也请告诉我。 谢谢你,

穆拉特

We are having difficulty reading configuration section of our Azure App Service from the code. We have a specific need to read a flag from App Service's own configuration section. I have added the new property in Azure Portal to the App Service's Configuration section. I am following
https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal

and

https://learn.microsoft.com/en-us/azure/app-service/configure-language-dotnetcore?pivots=platform-windows#access-environment-variables

To read the variables as environment variables but with no luck.

I also want to mention that we are trying to read the configuration variables from our .NET Core 3.1 application and I have implemented the following three different ways to read the variable with all being unsuccessful:

var authType = configuration["AUTHTYPE"];

var authType2 = configuration.GetValue("AUTHTYPE");

var authType3 = Environment.GetEnvironmentVariable("AUTHTYPE");

AUTHTYPE is the name of the configuration in the local configuration section of the app service. I have tried reading this configuration as "AUTHTYPE", "ASPNETCORE_AUTHTYPE" and "APPSETTING_AUTHTYPE" and all have failed to retrieve the value.

Please help us on how to access these variables as this problem is currently blocking us.
Please also let me know if you need more information or details.
Thank you,

Murat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2025-01-21 08:27:39

要解决此问题,请确保您已在 Azure 门户中设置以下解决方法。

导航到 Azure 门户>配置>新建应用程序设置并添加 ASPNETCORE_ENVIRONMENT

在此处输入图像描述

并确保您的应用程序中应该有 appsettings.json 文件

输入图片此处说明

如需完整设置,请参阅以下链接:

To get the rid of the issue ,Please make sure that below workaround you have setup in Azure portal.

Navigate to Azure Portal > Configuration > New Application setting and add ASPNETCORE_ENVIRONMENT

enter image description here

And make sure that in your application should have appsettings.json file

enter image description here

For complete setup please refer the below links:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文