Download DOWNLOAD
Forums FORUMS
Blogs BLOGS
Forge FORGE
Help HELP
Marketplace MARKETPLACE
DotNetNuke Home
You are here >   Community > Blogs
Register  |  Login

DNN Blog

May 28

Posted by: Charles Nurse
5/28/2008 

Michael Washington in a blog about updating his sites made reference to the fact that you no longer need to manualy modify your web.config settings prior to upgrading a site.

Why is this?  The answer is a new class that was introduced into the core (in 4.6.0) called XmlMerge.  This class is designed to allow developers to create xml files that can be used to "update" one of the core "config" files, and is especially useful for upgrades or component installations.

We have had the ability for some time to provide cleanup files - these files are named xx.xx.xx.txt and contain a list of folders and files to delete when upgrading to version xx.xx.xx.  This allows us to remove unneccessary files from production sites.  Starting in version 4.6.0 we added the ability to add a "xx.xx.xx.config" file which contained the changes required to "upgrade" a core config file.

Rather than try and explain - lets look at an example. The 4.6.0.config file:

<configuration>
    <nodes configfile="web.config">
        <node path="/configuration/system.web/httpModules" action="update" key="name" collision="overwrite">
            <add name="Compression" type="DotNetNuke.HttpModules.Compression.CompressionModule, DotNetNuke.HttpModules" />
            <add name="RequestFilter" type="DotNetNuke.HttpModules.RequestFilter.RequestFilterModule, DotNetNuke.HttpModules" />
            <add name="UrlRewrite" type="DotNetNuke.HttpModules.UrlRewriteModule, DotNetNuke.HttpModules" />
            <add name="Exception" type="DotNetNuke.HttpModules.Exceptions.ExceptionModule, DotNetNuke.HttpModules" />
            <add name="UsersOnline" type="DotNetNuke.HttpModules.UsersOnline.UsersOnlineModule, DotNetNuke.HttpModules" />
            <add name="DNNMembership" type="DotNetNuke.HttpModules.Membership.MembershipModule, DotNetNuke.HttpModules" />
            <add name="Personalization" type="DotNetNuke.HttpModules.Personalization.PersonalizationModule, DotNetNuke.HttpModules" />
        </node>
        <node path="/configuration/dotnetnuke/friendlyUrl/providers" action="update" key="name" collision="overwrite">
            <add name="DNNFriendlyUrl"
                 type="DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider, DotNetNuke.HttpModules"
                 includePageName="true"
                 regexMatch="[^a-zA-Z0-9 _-]" />
        </node>
    </nodes>
</configuration>

In version 4.6 - the HttpModules were all merged into a single assembly - the web.config file therefore needed to be updated to reflect this.  In this config file - there are two "node" elements which are the building blocks of the XmlMerge file.  The attributes tell the XmlMerge class how to deal with the content inside the node. 

So for the first node we have:

  • path="/configuration/system.web/httpModules" - this is an Xpath path that identifies the node being modified in the target file - in this case the "httpModules" element in the system.web element of the configuration
  • action="update" - this is the action - in this case the existing element is being "updated"
  • key="name"  - this is the key to use - in this case "name" - the XmlMerge class will identify the child nodes to change by matching the name attribute "Compression", "Exception etc.
  • collision="overwrite" - this is the behaviour to use if the child node exists - in this case the old entry will be overwritten by the new one

The target file is "web.config" as identified by the configfile attribute on the outer nodes element.

In addition to using this in the core Installer/Upgrader - the new "Universal Extension Installer" supports this ability too.  Again - as an example lets look at a fragment of a manifest from the new installer.

                    <config>
                        <configFile>web.config</configFile>
                        <install>
                            <configuration>
                                <nodes>
                                    <node path="/configuration/dotnetnuke/caching/providers" action="update" key="name" collision="overwrite">
                                        <add name="BroadcastPollingCachingProvider"
                                             type="DotNetNuke.Services.Cache.BroadcastPollingCachingProvider.BPCachingProvider, DotNetNuke.Caching.BroadcastPollingCachingProvider"
                                             providerPath="~\Providers\CachingProviders\BroadcastPollingCachingProvider\" />
                                    </node>
                                </nodes>
                            </configuration>
                        </install>
                        <uninstall>
                            <configuration>
                                <nodes>
                                    <node path="/configuration/dotnetnuke/caching/providers/add[@name='BroadcastPollingCachingProvider']" action="remove" />
                                </nodes>
                            </configuration>
                        </uninstall>
                    </config>

In this example (part of the manifest for installing the BroadcastPollingCachingProvider) you can see that the manifest defines a "config" element - which tells the Installer that we are "updating" a config file.  It has two separate sections that correspond to the same basic structure as the XmlMerge file above, one for installing the provider - with a similar set of attributes, and one for uninstalling, which shows how you would remove a section of the config file.

A full description of the API is beyond the scope of this blog, but if you want to start learning how to use this in your own modules/extensions - I would suggest that you look for the "XmlMerge.vb" file in the DotNetNuke project - the main entry points are the "UpdateConfig" methods.

 

Tags:

12 comment(s) so far...

Re: XmlMerge - what is it?

So, in summary, what you're saying is:
You can use the straight up Upgrade package, and DNN will handle the web.config changes? Is that correct?

By christoc on   5/28/2008

Re: XmlMerge - what is it?

I hope that what people take away from this is that not only is this great for DNN upgrades, but it positions DNN to allow module developers to deploy complex modules in a manner that is easy for the portal administrator. Editing web.config files is not an easy task and causes most of the problems when it is required.

By AdefWebserver on   5/28/2008

Re: XmlMerge - what is it?

Charles,

This is an awesome bit of functionality that I'm quite sure not very many of us knew about....

...runs off to go update his own blog.....

By mitchel.sellers@gmail.com on   5/28/2008

Re: XmlMerge - what is it?

It was only mentioned in passing in one of Joe's blogs (maybe one line and a link to the Gemini enhancement), but I did speak about it in my Open Force Europe talk last year :)

By cnurse on   5/28/2008

Re: XmlMerge - what is it?

I'm hesitant to endorse module developers from modifying the web.config, without the user's knowledge or consent. It seems like a pandora's box o' problems waiting to happen.

By ech01 on   5/28/2008

Re: XmlMerge - what is it?

@ech01 you can change web.config when installing modules in a number of ways. For example when adding the first instance of a module in one page. When you install a module you give it access to your entire DNN install, thus it is only available for host users. The XML Merge only makes it easier for some scenarios to work.

By hooligannes on   5/28/2008

Re: XmlMerge - what is it?

In the past I added comments with my initials (DWS) on a line of code above my changes, often with the original like commented out for reference. I then used WinMerge to visually merge my changes with release.config to make a new web.config. I just tried this to upgrade from DNN 4.8.0 to 4.8.3 and it worked flawlessly. However, there weren't many changes to release.config between 4.8.0 and 4.8.3.

The methodology that you describe appears that it would not mess with my comments although it COULD change the values of the web.config line I modified.

However, it sounds as if the DNN developer must gin up the file changes by hand for the actual changes to release.config. Does he have to do this by hand or is this automagic?

In a previous UNIX life (~1993) we used to do this for the /etc/*.config files by keeping a hidden version and using RCS's merge to merge the customers changes with ours. It worked very well.

Regards,
DaveS

By DavidWSnow on   5/29/2008

Re: XmlMerge - what is it?

I just upgraded two DNN instances from 4.8.2. to 4.8.3. As always, I manually copied my (currently) 9 web.config edits manually to the new web.config from the Install.zip package, then copied over, etc. Are you saying that this manual copying of changes is no longer necessary? I can use the Upgrade.zip package and ALL my web.config edits will be maintained? MachineKey, SQL connectionStrings, httpModules, httpRunTime settings, etc? I admit this seems a bit hard to believe. I guess I need some confirmation, clarification, and a little rephrasing before I can accept this. Thanks in advance - Jeremy

By jfarrance on   5/29/2008

Re: XmlMerge - what is it?

See Mitchel Sellers Blog at http://www.mitchelsellers.com/Blogs/tabid/54/articleType/ArticleView/articleId/216/Streamlined-Upgrades-from-462-and-Later.aspx for upgrade instructions.

/DaveS

By DavidWSnow on   5/30/2008

Re: XmlMerge - what is it?

Wow, so cool. I can't wait for 4.8.4 so I can see this work. If there was a book entitled "The 7 Habits of a Highly Effective (and Efficient) DotNetNuke Host/Admin/Professional" and in that book there is an entire chapter is devoted to staying up to date with new features in the product... Can someone give me a brief summary of that chapter? I visit these DNN blogs about once a week. What else should I be doing? Maybe a few knowledgeable core team members could take control of http://twitter.com/DotNetNuke and use that to aggregate the important 'events' that we should know about (taking equally great care to avoid the chatter, white-noise, and the occasional din of self-importance-postings? Also avoiding the bleeding edge and sticking to the solid and tested zone known as the cutting edge (I prefer not to bleed). I admit to having a slight smirk on my face because I realize the reply to this post might be another one that starts off with "See Firstname Lastname's Blog/Forum post at..."

By jfarrance on   5/30/2008

Re: XmlMerge - what is it?

I can't get it to pick up the change file and process this. In your post you state it is for module developers as well. So I went ahead and added xx.xx.xx.config to my zip and declared it in the manifest. Note the manifest is a dotnetnuke version="3.0" type="Module" manifest. I epxected it to be processed just like the .txt and sql files, but nothing happened. Any ideas?

- edit: I may well have misread the post. You were just referring to the core upgrade process that picks up on the xx.xx.xx.config files.

By Peter Donker on   5/20/2009

Re: XmlMerge - what is it?

Hi.
The question is related to 4.6.*.
For example I have the following file (in my module archive):
01.00.00.config
with content:



And i should remove handler during module uninstall:

What file (in my module archive) should contain specified expression?

By Override on   8/19/2009

Networks

Follow DNNCorp on Twitter

LinkedIn

Follow us on Twitter @DNNCorp or join the DotNetNuke Community on LinkedIn

Sponsors

DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation

Hosted by MaximumASP