我有一个使用 Entity Framework Core 的 ASP.NET Core 8 Web API。我在 Azure Linux 服务应用程序上部署我的应用程序。
我的 API 连接到 Azure SQL Server 数据库。我在我的应用服务上使用了用户管理的身份,并将其添加到 BDD 中。
我的问题是,我找不到如何在 .NET 8 中使用连接管理用户标识以及字符串连接的格式应该是什么。
我的问题是我没有找到如何在 .NET 8 中使用 连接管理的用户身份以及该信息的格式应该是什么 字符串连接。
Authentication
参数,后跟您的 Database
名称和 ClientIdOfManagedIdentity
的 UserId
基本上,我们有两种方法来处理托管身份:
您的连接字符串应具有以下格式:
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"
}
注意:请参考此官方文档以获取更多示例和格式。