I am damn sure that you must sometimes face this problem
during reading, finding or modifying any entry in Sitecore web.config file.
The config file that I have contains 3950 lines. WTF
how to work with such a large file. Is there any way to break it so that I can
make my own settings value in other config file.
Fortunetly YES. Here is the trick.
·
Create one config file like "Sample.config"
in "Website\App_Config\Include" folder and make keys entries
in <settings> … </settings>
section as
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="EnableLogin" value="true"/>
<setting name="mykeyName" value="KeyValue"/>
</settings>
</sitecore>
<system.web>
</system.web>
</configuration>
At runtime Sitecore merge all these config files and
treat them as a single file and work smartly.
And now the million dollar question, How to access it
in C# code?
Simply refer GetSetting()
method of Settings class as below
string strKeyValue = Sitecore.Configuration.Settings.GetSetting("mykeyName");
Please leave your comments or share this trick if it’s useful for you.
No comments:
Post a Comment