You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为EventGrid Domain添加用户分配的托管标识?

解决Azure.ResourceManager创建EventGrid Domain时添加用户分配托管标识的问题

要给EventGrid Domain分配用户分配的托管标识,核心是正确配置ManagedServiceIdentity中的UserAssignedIdentities字典。尽管UserAssignedIdentity类只有无参构造且属性只读,但创建时只需将用户分配标识的资源ID作为字典的键,值用无参构造的UserAssignedIdentity实例即可,Azure后台会根据这个ID自动关联对应的标识。

修改后的完整代码示例

ArmClient client = new(new DefaultAzureCredential());

// 替换为你的用户分配托管标识的完整资源ID
string userAssignedIdentityResourceId = "/subscriptions/{你的订阅ID}/resourceGroups/{目标资源组名}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{标识名称}";

var domainToUpdate = new EventGridDomainData(_azureSettings.DefaultLocation)
{
    InputSchema = EventGridInputSchema.EventGridSchema,
    Identity = new Azure.ResourceManager.Models.ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned)
    {
        UserAssignedIdentities = new Dictionary<string, UserAssignedIdentity>()
        {
            // 添加用户分配标识:键为资源ID,值为无参构造实例
            { userAssignedIdentityResourceId, new UserAssignedIdentity() }
        }
    }
};

// 执行Domain创建操作(示例)
var resourceGroup = client.GetResourceGroupResource(new ResourceIdentifier("/subscriptions/{订阅ID}/resourceGroups/{目标资源组名}"));
var domainCollection = resourceGroup.GetEventGridDomains();
await domainCollection.CreateOrUpdateAsync(WaitUntil.Completed, "你的Domain名称", domainToUpdate);

关键说明

  • UserAssignedIdentity的PrincipalId、ClientId等属性是Azure服务在创建完成后返回的只读字段,创建阶段无需手动设置。
  • 字典的键必须是用户分配托管标识的完整资源ID,确保Azure能准确定位到目标标识。

内容的提问来源于stack exchange,提问作者MadSkeletor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 08:19:59