0
votes

I have hosted Azure Web Job inside Azure Web Apps which runs every hour and I need to write the Web Job Run time as key value pair. Next time when Webjob run then it will pick the last run time and do its operations. I was thinking of adding Key Value pair in Azure AppSettings of Azure App Service but I am not able to fine any code to update the value in Azure AppSettings.

Can anyone please let me know the code? Please let me know if it is good approach or should I go for Azure Storage Container to store Last Batch Run Time value.

1
Wouldn't it be simpler to put the KV pair in Azure Table storage?Simon

1 Answers

1
votes

but I am not able to fine any code to update the value in Azure AppSettings.

You could use Microsoft.WindowsAzure.Management.WebSites to achieve it.

var credentials = GetCredentials(/*using certificate*/);
using (var client = new WebSiteManagementClient(credentials))
{
    var currentConfig = await client.WebSites.GetConfigurationAsync(webSpaceName,
                                                                    webSiteName);
    var newConfig = new WebSiteUpdateConfigurationParameters
                    {
                        ConnectionStrings = null,
                        DefaultDocuments = null,
                        HandlerMappings = null,
                        Metadata = null,
                        AppSettings = currentConfig.AppSettings
    };
    newConfig.AppSettings[mySetting] = newValue;
    await client.WebSites.UpdateConfigurationAsync(webSpaceName, webSiteName,
                                                   newConfig);
}

Or using Azure Fluent Api, refer to this SO thread.