我正在尝试为自定义模块创建设置。我正在从版本8升级到版本9.代码适用于版本8.我正在测试default2.aspx上的代码。这是我的代码和错误:
错误:
找不到关键名称'AvalaraJMALicenseKeyStartDate'的全局设置
代码显示错误:
SettingsKeyInfoProvider.SetSettingsKeyInfo(si);
代码:
//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);
}
答案 0 :(得分:0)
我删除了此代码并且有效:
si.SiteID = siteID;
si.KeyIsGlobal = false;