Azure 连接字符串不会覆盖 appsettings.json

标签 azure azure-devops .net-6.0 azure-configuration

我使用的是.NET 6.0,在项目中我有 appsettings.json 文件,其中包含以下行:

"ConnectionStrings": {
        "SqlConnection": "Server=.\\SQLEXPRESS;Database=XXX;Trusted_Connection=True;MultipleActiveResultSets=true"
},

在 Azure 中,我的连接字符串定义如下:[ enter image description here ] 1

当我检查 xxx.scm.azurewebsites.net/wwwroot 中的 appsettings.json 时,我可以看到它仍然使用在我的项目的 appsetting.json 中定义的 ConnectionString,但不在 Azure 中定义。

我的数据库上下文:

services.AddDbContext<MyContext>(
            options => options.UseSqlServer(Configuration.GetConnectionString("SqlConnection")));

如何在 Azure 中覆盖我的连接字符串并使用它?谢谢。

最佳答案

应用服务不会更改您的 appsettings.json 文件。除了 appsettings.json 文件之外,它还会将任何应用设置(包括连接字符串)注入(inject)到您的应用程序中(作为 ENV 变量)。

关于Azure 连接字符串不会覆盖 appsettings.json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74657480/

相关文章:

rest - Azure服务总线: limitations to send a batch via the REST API?

azure - Azure DevOps 白名单的 IP 列表

tfs - 使用 OpsHub 从本地 TFS2012 迁移到 VSO TFS2013

azure-devops - Azure 开发运营 : deploy using web deploy

macos - .NET 6 - msbuild 在 VS2022 for Mac 上使用了错误的 SDK

azure - 无法从基于 Java 的 Rest API 访问 SharePoint 图形 API

powershell - 无法从远程计算机在 Windows Server 2012 R2 中执行 DSC 文件

azure - Service Fabric 具有多个用于服务远程处理的通信监听器

asp.net-core - 如何在 .net6 中使用 WebApplicationFactory(没有口语入口点)

.net - 软件包安装在 docker 内,但实际命令提供异常