Web Config Transformation Syntax

3.1k Views Asked by At

I've been following the MSDN guide for Web Config Transformation and by-and-large have had success with it.

However, one line of my web config is giving my troubles and I can only assume it's because I'm misunderstanding the guide and using the wrong syntax.

I'm hopeful that someone will be able to point out my mistake, and will be grateful if that's the case.

The offending line in the transform is:

<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />

The line in the original web config is:

<sessionState mode="SQLServer" sqlConnectionString="data source=networkAlias;uid=userId;pwd=password;" cookieless="UseDeviceProfile" timeout="120" />

My hope was that the transform would replace the attribute "sqlConnectionString", changing the connection details. Unfortunately the line is unaffected.

I've used exactly the same syntax for:

<network host="localhost" xdt:Transform="SetAttributes(host)" />

The above works just fine, so I had assumed it would be the case for the too.

Can anyone see where I'm going wrong?

2

There are 2 best solutions below

0
On BEST ANSWER

After taking a break and coming back to it with some fresh eyes, I realised that the syntax was in fact just fine.

The problem was that at some point - no idea when - the element had been moved (maybe a copy/paste error by myself or another team member) out of the element where it belonged, so it was just hanging there and not where it should have been.

Once I moved back into where it should have been, problem solved, the transform was correctly detecting the element again and applying the transform.

So, lesson learned: if a transform is mysteriously not being applied to one element (when it works just fine on another), check to make sure the element is correctly situated.

5
On

Just a simple typo. You need to change sqlConnectionString to stateConnectionString. You have it right in the web.config, but not the transformation. Otherwise, the transform looks good.

You need to change sqlConnectionString here:

<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />

To stateConnectionString:

<sessionState stateConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(stateConnectionString)" />