Create EventHub from a web app

Stephan Wedig 1 Reputation point


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($"{tenantId}/");

var token = await context.AcquireTokenAsync(
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
Azure Event Hubs
An Azure real-time data ingestion service.
567 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Stanislav Zhelyazkov 21,506 Reputation points MVP

    Most likely the credentials you are using does not have permissions.