0

我正在尝试为自定义模块创建设置。我正在从版本 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);

        }
4

1 回答 1

0

我删除了这段代码,它起作用了:

si.SiteID = siteID;
si.KeyIsGlobal = false;
于 2016-07-24T22:09:26.950 回答