我已经将Azure Web Job托管在每小时运行一次的Azure Web Apps中,我需要将Web Job Run time编写为键值对。下次Webjob运行时,它将选择上次运行时间并执行其操作。我当时正在考虑在Azure App Service的Azure AppSettings中添加键值对,但无法对任何代码进行更新以更新Azure AppSettings中的值。
有人可以让我知道代码吗?请让我知道这是一种好方法还是应该让Azure存储容器存储“上次批处理运行时”值。
但是我无法调整任何代码来更新Azure AppSettings中的值。
您可以使用Microsoft.WindowsAzure.Management.WebSites实现它。
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);
}
或使用Azure Fluent Api,请参考此SO thread。