I am trying to create settings for a custom module. I am upgrading from Version 8 to version 9. The code worked fine for version 8. I am testing the code on default2.aspx. Here is my code and error:
Error:
Global setting was not found for key name 'AvalaraJMALicenseKeyStartDate'
The code shows the error here:
SettingsKeyInfoProvider.SetSettingsKeyInfo(si);
Code:
//Insert new SettingsKey into database
string siteName = CMS.SiteProvider.SiteContext.CurrentSiteName;
int siteID = CMS.SiteProvider.SiteContext.CurrentSiteID;
DataSet sites = CMS.SiteProvider.SiteInfoProvider.GetSites();
/// <summary>
/// creates custom settings for JMA Kentico Software in settings area of site manager
/// </summary>
public void CreateAvalaraSettings()
{
//create the avalara category, if it doesn't exist
SettingsCategoryInfo category = SettingsCategoryInfoProvider.GetSettingsCategoryInfoByName("JMA.Avalara");
if (category == null)
{
SettingsCategoryInfo se = new SettingsCategoryInfo();
se.CategoryName = "JMA.Avalara";
se.CategoryDisplayName = "Avalara";
SettingsCategoryInfoProvider.SetSettingsCategoryInfo(se);
}
#region avalara settings
//if the setting does not exist, then create it
if (SettingsKeyInfoProvider.GetSettingsKeyInfo(siteName + ".AvalaraJMALicenseKeyStartDate", siteID) == null)
{
// Create and set up new SettingsKey
SettingsKeyInfo si = new SettingsKeyInfo();
si.KeyName = siteName + ".AvalaraJMALicenseKeyStartDate";
si.KeyDisplayName = "AvalaraJMALicenseKeyStartDate";
si.KeyDescription = "AvalaraJMALicenseKeyStartDate";
si.KeyType = "string";
si.KeyDefaultValue = DateTime.Now.ToString();
si.KeyValue = DateTime.Now.ToString();
si.SiteID = siteID;
si.KeyIsGlobal = false;
si.KeyCategoryID = category.CategoryID;
SettingsKeyInfoProvider.SetSettingsKeyInfo(si);
}
I removed this code and it worked:
si.SiteID = siteID;
si.KeyIsGlobal = false;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.