2016-07-23 54 views
0

我正在嘗試爲自定義模塊創建設置。我從版本8升級到版本9.代碼在版本8中運行良好。我正在測試default2.aspx上的代碼。這裏是我的代碼和錯誤:Kentico 9未找到密鑰名稱的全局設置

錯誤:

Global setting was not found for key name '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

你在哪一行得到錯誤?何時執行/調用代碼(app init或其他地方)? – rocky

+1

你收到的不是一個錯誤,它表明它找不到該密鑰。我立即注意到的一件事就是您的關鍵類別名稱,它不應以「CMS」作爲前綴。您應該使用自己的命名空間而不是'CMS'命名空間作爲文檔狀態。其次,「siteName」變量在哪裏填充,並且填充了正確的值? –

+0

嗨,我做了調整,我說什麼線引發錯誤。我的問題仍然存在。我還在檢查全局設置? –

回答

0

我刪除此代碼,它的工作:

si.SiteID = siteID; 
si.KeyIsGlobal = false;