SPWebConfigModification Sequence Numbers Do Not Work …

So I was doing some tidying up on SharePoint stuff we’d done at Ridgian this weekend, and I was trying to finish off a WebApplication feature which adds in all the web.config modifications needed to allow Silverlight to work. In the HttpHandlers section I kept the following being written:
 
 
 
 I actually wanted the <remove verb=”*” path=”*.asmx”> tag to be before the <add verb=”*” path=”*.asmx”> tag otherwise the settings may not function correctly as you might gather.  The code I had to setup the relevant modifications was as follows:
 
 
 

The ModificationEntry is a helper structure to bag up the configuration changes in a collection then submit them to be applied.

Notice the highlighted numbers?  That’s the Sequence number which in the MSDN help is described as follows:

“A sequence is used only if there is more than one modification of the same type to the same node or attribute. In this case, modifications with lower sequence numbers are applied first.”

Unfortunately that is incorrect! The sequence numbers seem to have absolutely zero impact, because no matter what I did my web.config would not come out how I wanted.  Searching around the internet nearly all examples do not set the sequence number, leaving it a zero.  Luckily via Bing my current favourite search engine I found these PowerPoint Slides courtesy of Blake Blackshear of Parivida Solutions. It’s a pretty comprehensive guide to carrying out modifications on the SharePoint web.config and lo and behold the answer I needed was in there.  I knew that the modifications were applied with a combination of Name + Xpath, and I could see that they were being applied always in alphabetical order, but some bright spark had thought “Right, we’ll use that!” and so following their example I changed my code to as follows:

 

Note the sneaky change to the XPath? Like their style and now my web.config looks just so …

Luverly.  Hope this helps someone out. Oh, and I will get that PRISM article done soon …

Cheers

Dave Mc

 

 

 

 
 
 
 

< DIV>

Advertisements

About davemcmahon81
Software Developer & Architect, User Group Leader, Speaker, Writer, Blogger, Occasional Guitarist, Man-made Global Warming Sceptic, Climate Change Believer, General Optimist but most of all proud Husband and Dad ...

4 Responses to SPWebConfigModification Sequence Numbers Do Not Work …

  1. hak says:

    Nice hack. But it has an issue which occurs if you have more then 10 items on one level. Its caused by the default sorting order:
    [1=1]
    [10=10]
    [2=2]

    I think the solution might be to compare strings e.g.:
    [’01’=’01’]
    [’02’=’02’]
    [’10’=’10’]

  2. yasir says:

    Thanks Dave. It worked. Nice solution

  3. Tal Winter says:

    MAN!!! You are a life saver!!

  4. niranjanrao says:

    Thanks dave.. great solution u saved my day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: