Most likely the credentials you are using does not have permissions.
Create EventHub from a web app
Hi,
actually I begin to develop some programms for Azure. I want to select from a specific event hub namespace the existing event hubs. I wrote the code below but I get the following error message when the program try execute line 9:
ErrorResponseException: Operation returned an invalid status code 'Forbidden'
Microsoft.Azure.Management.EventHub.EventHubsOperations.ListByNamespaceWithHttpMessagesAsync(string resourceGroupName, string namespaceName, Nullable<int> skip, Nullable<int> top, Dictionary<string, List<string>> customHeaders, CancellationToken cancellationToken)
var cred = new ClientCredential(clientId, secretName);
var context = new AuthenticationContext($"https://login.microsoftonline.com/{tenantId}/");
var token = await context.AcquireTokenAsync(
@"https://management.core.windows.net/",
cred
);
var serviceClientCredentials = new TokenCredentials(token.AccessToken);
var eventHubManagementClient = new EventHubManagementClient(serviceClientCredentials) {
SubscriptionId = subscriptionID
};
var eventhubs = eventHubManagementClient.EventHubs.ListByNamespace(resGroup, eventHubNamespace);
foreach (var eventhub in eventhubs)
Models.Add(new PizzaCreator { Name = eventhub.Name });
Has someone an idea where the problem could be?
Azure Event Hubs
1 answer
Sort by: Most helpful
-
Stanislav Zhelyazkov 27,716 Reputation points MVP Volunteer Moderator
2021-07-07T07:55:35.167+00:00