Amit Sharma
Amit Sharma

Reputation: 1088

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.

Upvotes: 5

Views: 10649

Answers (2)

Vlad Iobagiu
Vlad Iobagiu

Reputation: 4118

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>

Upvotes: 8

Martin Davies
Martin Davies

Reputation: 4456

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

Sitecore.Configuration.Settings.GetAppSetting()

Upvotes: 3

Related Questions