.NET 8 Azure 数据库用户管理身份

问题描述 投票:0回答:1

我有一个使用 Entity Framework Core 的 ASP.NET Core 8 Web API。我在 Azure Linux 服务应用程序上部署我的应用程序。

我的 API 连接到 Azure SQL Server 数据库。我在我的应用服务上使用了用户管理的身份,并将其添加到 BDD 中。

我的问题是,我找不到如何在 .NET 8 中使用连接管理用户标识以及字符串连接的格式应该是什么。

azure entity-framework-core asp.net-core-webapi .net-8.0 user-management
1个回答
0
投票

我的问题是我没有找到如何在 .NET 8 中使用 连接管理的用户身份以及该信息的格式应该是什么 字符串连接。

根据您的场景和描述,如评论中所述,您应该有

Authentication
参数,后跟您的
Database
名称和
ClientIdOfManagedIdentity

的 UserId

基本上,我们有两种方法来处理托管身份:

  1. 系统分配的托管身份和
  2. 用户分配的托管身份

您的连接字符串应具有以下格式:

string ConnectionString1 = @"Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; Database=YourDbName";

using (SqlConnection conn = new SqlConnection(ConnectionString1)) {
    conn.Open();
}

appsettings.json:

"ConnectionStrings": {
  "DefaultConnection": "Server=demo.database.windows.net; Authentication=Active Directory Managed Identity; Encrypt=True; Database=YourdatabaseName"
}

注意:参考此官方文档以获取更多示例和格式。

© www.soinside.com 2019 - 2024. All rights reserved.