Retrieving settings from web.config in sitecore

I want to get global settings from the web.config file in the sitecore solution, I write the setting in the configuration file and can see its entry in showconfig. when I try to get its value, it does not give the corresponding value. my code looks like this:

var newsBodyTemplateID = Sitecore.Configuration.Settings.GetSetting("NewsBody"); 

when I evaluate this, it gives this message: enter image description here

what I am missing can understand this.

+5
source share
2 answers

This method will return the settings from the Sitecore\Settings node. There is another way to get AppSettings .

 Sitecore.Configuration.Settings.GetAppSetting() 
+3
source

First of all, I do not recommend adding your settings to web.config. If you want to update Sitecore, you must manually combine your web.config.

If you still want to add settings to web.config, you need to have something like:

  <configuration> ..... <appSettings> <add key="YourSeetings" value="your value" /> ... </appSettings> ..... </configuration> 

From c # code you need to use

 ConfigurationManager.AppSettings["YourSeetings"] 

If you have your own settings in the / configuration / sitecore / settings section, you need to use C # code:

 Sitecore.Configuration.Settings.GetSetting("yoursettingsname"); 

Your configuration file will look like this:

  <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> <sitecore> <!-- General settings --> <settings> <setting name="YourSettingsFieldName" value="{1EPR25B2-98C6-45BF-B9E4-824ECAAEF499}" /> </settings> </sitecore> </configuration> 
+6
source

All Articles