gpt4 book ai didi

c# - 在适用于 .NET 的 Azure 管理库中创建具有多个声明的 Azure 服务总线策略

转载 作者:行者123 更新时间:2023-12-03 05:46:26 27 4
gpt4 key购买 nike

我正在使用Azure Management libraries for .NET使用 Azure 服务总线。我的目标是创建一个包含发送监听声明的共享访问策略。我可以在 Azure 门户中执行此操作。

Policy created in the azure portal

IServiceBusNamespace serviceBus = ...
IBlank policyDefinition = serviceBus.AuthorizationRules.Define("MySendAndListenPolicy2");

IBlank我可以调用WithListeningEnabled()WithSendingEnabled()。两者都返回一个 IWithCreate,我只能从中创建规则(即 Create()CreateAsync()。似乎没有是配置发送监听的选项。

如何使用 Azure Management .NET SDK 创建具有发送监听的策略?

最佳答案

我通过使用 Fluent API 的 Inner 对象实现了这一点。

// using Microsoft.Azure.Management.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent;
// using Microsoft.Azure.Management.ServiceBus.Fluent.Models;

string policyName = "ListenAndSendPolicy";

// Define the claims
IList<AccessRights?> rights = new List<AccessRights?>();
rights.Add(AccessRights.Send);
rights.Add(AccessRights.Listen);

// Create the rule
SharedAccessAuthorizationRuleInner rule = await serviceBus.AuthorizationRules.Inner.CreateOrUpdateAuthorizationRuleAsync(
serviceBus.ResourceGroupName,
serviceBus.Name,
policyName,
rights);

// Get the policy
policy = await serviceBus.AuthorizationRules.GetByNameAsync(policyName);

政策创建成功

enter image description here

关于c# - 在适用于 .NET 的 Azure 管理库中创建具有多个声明的 Azure 服务总线策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53479256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com