【发布时间】:2020-07-07 11:27:22
【问题描述】:
我正在使用https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent 以编程方式(C# .NET-Core Web 应用程序)在 Azure 中获取资源,并尝试通过提供如下服务主体来获取资源信息......
string subscriptionId="XXX";
AzureCredentials cred = new
AzureCredentialsFactory().FromServicePrincipal(UIConstants.ClientID,
UIConstants.Secret, UIConstants.Tenant,AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(cred)
.WithSubscription(subscriptionId);
当我试图获得这样的 Active Directory 用户总数时:
int identity = azure.AccessManagement.ActiveDirectoryUsers.List().ToArray().Length;
我在代码中遇到了这个异常:
操作返回无效的状态代码“禁止”
请帮我解决上述问题..
谢谢, 图图尔
【问题讨论】:
-
为不完整的问题道歉。异常即将到来,因为“操作返回了无效的状态代码'禁止'”。
-
表示你没有足够的访问权限来枚举所有AAD对象(另外请注意AAD不是AD)
-
感谢@Dai 重播。但是,我可以访问其他 azure 资源信息,例如 vm、storages。您能否详细说明并提供更多详细信息..?谢谢,
-
仅仅因为您的访问令牌/用户有权访问虚拟机和存储并不意味着您有权访问所有用户。检查您在进行身份验证时请求的权限,并在 Azure 门户中检查您的用户权限。
标签: c# azure .net-core azure-management-api