Utilizing Configuration With Azure Perform
Generally we have to retailer configuration knowledge in our Azure Perform which we will reference. In our Azure Perform, this configuration knowledge consists of storing server urls, connection strings, credentials and many others. That is very helpful after we wish to deploy our Azure perform in numerous environments. We don’t must do any modifications in our Azure perform code, we will merely use Configuration to carry new particulars and our Azure perform might be utilizing the brand new particulars. Let’s see how we will use configuration in Azure perform.
- Replace your Azure perform to make use of ConfigurationManager.AppSetting
- Add all of the Azure perform settings in Azure Portal
Let’s say we wish to use software settings for blob container identify and for the weblog connection particulars. The very first thing we have to do is add reference to System.Configuration in our Azure perform, and after that we will use the next code.
- var BlobConnection = ConfigurationManager.AppSettings[“BlobConnection”];
- var Containername = ConfigurationManager.AppSettings[“Containername”];
Within the above code we’re utilizing two Keys, BlobConnection and Containername. We have to add configuration in Azure perform utilizing the identical key names. Equally we will use different keys in different strategies, for instance, within the beneath methodology we’re utilizing it to get related with Dynamics 365 CE.
- non-public static OrganizationWebProxyClient GetCRMService(TraceWriter log)
- var aadInstance = “https://login.microsoftonline.com/”;
- var organizationUrl = ConfigurationManager.AppSettings[“Dynamics365URL”];
- var clientId = ConfigurationManager.AppSettings[“ClientId”];
- var clientkey = ConfigurationManager.AppSettings[“Clientkey”];
- var tenantId = ConfigurationManager.AppSettings[“TenantId”];
- var clientcred = new ClientCredentials(clientId, clientkey);
- var authenticationContext = new AuthenticationContext(aadInstance + tenantId);
- var authenticationResult = authenticationContext.AcquireTokenAsync(organizationUrl, clientcred);
- var requestedToken = authenticationResult.Consequence.AccessToken;
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- var sdkService = new OrganizationWebProxyClient(GetServiceUrl(organizationUrl), new TimeSpan(30, 0, 0), false);
- sdkService.HeaderToken = requestedToken;
- return sdkService;
Now we’ve the code, we will add configuration settings utilizing Azure portal after deploying our Azure perform. Use the next steps,
- Open your Perform App
- Underneath your Perform App setting click on on the Configuration
- Click on on New software setting
- Add all of the Key- Values one after the other
- As soon as all of the configuration is added, click on on the Save button to save lots of your configuration.
Restart your perform app and it ought to refer all of the configurations you added.