© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
24 replies
v0fbu1vm

Azure Managed Identity

        if (!builder.Environment.IsProduction()) return;

        // Retrieve configuration settings
        var configuration = builder.Configuration;

        try
        {
            // Add Azure Key Vault
            var keyVaultEndpoint = new Uri(configuration[Configs.KeyVaultUrl]!);
            var azureCredential = new DefaultAzureCredential(new DefaultAzureCredentialOptions
            {
                ManagedIdentityClientId = Configs.ManagedIdentityClientId,
            });
            var secretClient = new SecretClient(keyVaultEndpoint, azureCredential);
            configuration.AddAzureKeyVault(secretClient, new KeyVaultSecretManager());
        }
        catch (Exception e)
        {
            Log.Error(e.Message);
        }
        if (!builder.Environment.IsProduction()) return;

        // Retrieve configuration settings
        var configuration = builder.Configuration;

        try
        {
            // Add Azure Key Vault
            var keyVaultEndpoint = new Uri(configuration[Configs.KeyVaultUrl]!);
            var azureCredential = new DefaultAzureCredential(new DefaultAzureCredentialOptions
            {
                ManagedIdentityClientId = Configs.ManagedIdentityClientId,
            });
            var secretClient = new SecretClient(keyVaultEndpoint, azureCredential);
            configuration.AddAzureKeyVault(secretClient, new KeyVaultSecretManager());
        }
        catch (Exception e)
        {
            Log.Error(e.Message);
        }
I have spent almost 8 hours trying to find the issue. For some reason managed identity is not working in production mode. It seems to be unable to load the secrets. Even though I have successfully defined the resource access polices. The code was working fine before I went to sleep. All of a sudden when I woke up its not working? Can anyone please help?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Azure - Postgre - EFCore Managed Identity
C#CC# / help
2y ago
Azure EventGrid Partner Topic Managed Identity access
C#CC# / help
8mo ago
❔ Azure DevOps API Authentication issue (Managed Identity)
C#CC# / help
3y ago
Using Azure Managed Identities API
C#CC# / help
3y ago