Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting setting from web.config in sitecore

i want to get global setting from web.config file in sitecore solution, i write setting in config file and able to see it's entry in showconfig. when i try to get it's value, it is not giving appropriate value. my code is like this:

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

when i evaluate this, it giving this message: enter image description here

what i'm missing here can some figure out it.

like image 202
Amit Sharma Avatar asked Aug 14 '15 07:08

Amit Sharma


2 Answers

First of all I don't recomment to add in web.config your settings. If you want to upgrade your Sitecore than you have to merge manually your web.config.

If you still want to add setttings in 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 settings on section /configuration/sitecore/settings you need to use from C# code :

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

Your config file will looks like :

 <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>
like image 104
Vlad Iobagiu Avatar answered Sep 20 '22 02:09

Vlad Iobagiu


That method will return settings from the Sitecore\Settings node. there is another method to get AppSettings.

Sitecore.Configuration.Settings.GetAppSetting()
like image 36
Martin Davies Avatar answered Sep 22 '22 02:09

Martin Davies