c# - 在 Azure Function v3 中获取连接字符串

标签 c# asp.net-core azure-functions connection-string application-settings

我很困扰。我想在 Azure v3 函数(.Net Core 3.1)中获取连接字符串。
我的本地设置看起来像

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
    },
    "ConnectionStrings": {
      "DefaultConnection": "bla bla"
    }
}
在我做的功能中
string defaultConnection = Environment.GetEnvironmentVariable("ConnectionStrings:DefaultConnection");
这在本地工作正常,但在 Azure 上,defaultConnection 为空。我在函数的应用程序设置的连接字符串部分下定义了连接。
enter image description here
我的方法对 Azure 函数 v3 是否正确?

最佳答案

您需要指定连接字符串前缀(请参阅 documentation ):

Environment.GetEnvironmentVariable("CUSTOMCONNSTR_DefaultConnection");

关于c# - 在 Azure Function v3 中获取连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62406026/

相关文章:

c# - 在Emgu + OpenCV中处理带有多个子图像的图像的最佳方法?

c# - 如何通过手动验证使 MobileNo、EmpOfficeCode 等实体在 EF core Razor 页面中唯一

Azure Functions V2 每次发布前都必须停止函数,因为 dll 正忙

azure - 使用 AAD 和 Azure Function 的 Easy Auth 隐式流程返回未经授权

c# - 设计 C# SOAP API 客户端/包装器

c# - 自定义验证属性 MVC2

c# - Xamarin Forms Nullable 属性 - 未将对象引用设置为对象的实例

asp.net-core - 在运行时更改注入(inject)的对象

error-handling - 在错误处理操作中如何确定我应该返回 web View 还是 api 响应

azure - 通过 ARM 模板覆盖现有 azure 功能应用程序的 appSettings