The Sitecore web.config is very big. Actually, it’s so big that Sitecore have decided to split the file into several files. If you look in your /App_Config folder, you will notice a lot of .config files. All of these files (except for the ConnectionStrings.config) are actually merged into the web.config at run-time.
Sitecore also has an “auto-include” feature. Take a look at the “Include” folder. All .config files in this folder will be merged at runtime. There is some major advantages to this:
- Seperate your own settings from Sitecore settings. You no longer has to look for your settings in the huge web.config file.
- Deploy management. You can have seperate .config files for your development, test and production. Simply copy the appropriate files to the appropriate environment (note: We don’t use that in Pentia. We have an even smarter continous integration environment)
- No web site restart when updating configuration. That’s right. The web site does not restart when changing settings in config files in the Include folder.
What can you do then? There is some limitations though:
- You can only update the /configurations/sitecore section.
- Includes are “auto-overwriting”. New elements are added. Existing elements will be overwritten.
- You cannot delete settings.
Here is a simple file, adding 3 commands:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/"> <sitecore> <commands> <command name="pt:unlockall" type="PT.Locks.Commands.UnlockAll, PT.Locks" /> <command name="pt:unlockothers" type="PT.Locks.Commands.UnlockOthers, PT.Locks" /> <command name="pt:unlockitem" type="PT.Locks.Commands.UnlockItem, PT.Locks" /> </commands> </sitecore> </configuration>
Inserting elements at specific position can be done using patch:before and patch:after attributes:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/"> <sitecore> <processors> <uiRenameItem> <processor patch:after="*[@method='CheckLinks']" mode="on" type="PT.Function,PT.Library" method="MyFunction" /> </uiRenameItem> </processors> </sitecore> </configuration>
Here is another example, inserting an event:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/"> <sitecore> <events> <event name='item:saving'> <handler type="PT.PermanentRedirect.ItemSaveHandler,PT.PermanentRedirect" method="AddRedirectRecord" /> </event> </events> </sitecore> </configuration>
Inserting as the first element can be done using the patch:before=’*[1]’ attribute:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/"> <sitecore> <pipelines> <uiDragItemTo> <processor patch:before="*[1]" mode="on" type="PT.Pipeline,PT.Code" method="AddRedirectRecord" /> </uiDragItemTo> </processors> </sitecore> </configuration>
You can use the ShowConfig tool located in the /sitecore/admin/ folder to see the complete merged web.config:
http://[yourwebsite]/sitecore/admin/showconfig.aspx
For further reading, see Mark Cassidy’s blog post, or read the Sitecore SDN Faq on the topic.
Very well explained Brian. A minor comment, from 6.3 the app does restart when modifying an include file.
LikeLike
Pingback: XAML (SheerUI) dialog in Sitecore 6.3.x « Brian Pedersen’s Sitecore and .NET Blog
Pingback: Sitecore Include Files | TCSC Blog
Pingback: Sitecore DMS uses master database per default « Brian Pedersen’s Sitecore and .NET Blog
Pingback: Open Media Library from Sitecore Page Editor « Brian Pedersen’s Sitecore and .NET Blog
Pingback: Open Sitecore Content Editor from the Page Editor « Brian Pedersen’s Sitecore and .NET Blog
Pingback: Sitecore Custom Google Map Field | #Just Another Place To Stop By
Pingback: The type initializer for ‘Sitecore.Diagnostics.LoggerFactory’ threw an exception | Sitecore basics!
Pingback: Sitecore Custom Search | Learn and share
Pingback: Sitecore Code Generator and O/R mapper | Brian Pedersen's Sitecore and .NET Blog
Pingback: Sitecore Advanced Configuration in .config files | Brian Pedersen's Sitecore and .NET Blog
Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog