Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure vault key using .Net 4.5

Tags:

c#

asp.net

azure

I have an Azure account and I need to do this using.NEt 4.5 class library

  • Create Key Vault Resource
  • Add Secrets to the Key Vault
  • Provision Web App Infrastructure
  • Create a Managed Service Identity
  • Build an ASP.NET Core Web App
  • Deploy and Validate the Web App

I have found few articles but no complete articles or mostly using asp.net Core. I need to create it using .Net 4.5

Can you please suggest solution?

like image 388
Asif Hameed Avatar asked Jan 31 '26 19:01

Asif Hameed


1 Answers

We can use Microsoft.Azure.Management.Fluent library to manage Azure resources (https://www.nuget.org/packages/Microsoft.Azure.Management.Fluent/)

Combined with ARM template for each of the resources (KeyVault, WebApp and any other resource) we can create the resource by calling the Fluent library for each template

Providing sample code below for creating Storage Account using Fluent library

string tenantId = "";
string clientId = "";
string clientSecret = "";
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Configure().WithLogLevel(Microsoft.Azure.Management.ResourceManager.Fluent.Core.HttpLoggingDelegatingHandler.Level.Basic).Authenticate(credentials).WithSubscription("<<subscriptionid>>");

var templateString = File.ReadAllText("storageaccountARMTemplate.json");
var resourceName = "storageaccounttemplate";
var resourceGroupName = "rglearnazure";
            azure.Deployments.Define(resourceName).WithExistingResourceGroup(resourceGroupName).WithTemplate(templateString).WithParameters("{}").WithMode(DeploymentMode.Incremental).Create();
like image 189
akb Avatar answered Feb 02 '26 09:02

akb