Web 配置转换语法

发布于 12-12 04:21 字数 843 浏览 1 评论 0原文

我一直在关注Web Config Transformation的MSDN指南,并且大体上已经有了成功了。

然而,我的网络配置中的一行给我带来了麻烦,我只能假设这是因为我误解了指南并使用了错误的语法。

我希望有人能够指出我的错误,如果是这样,我将不胜感激。

转换中的违规行是:

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

原始 Web 配置中的行是:

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

我希望转换能够替换属性“sqlConnectionString”,从而更改连接详细信息。不幸的是,线路没有受到影响。

我使用了完全相同的语法:

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

上面的效果很好,所以我假设它也是如此。

谁能看到我哪里出错了?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓦然回首2024-12-19 04:21:10

只是一个简单的错字。您需要将 sqlConnectionString 更改为 stateConnectionString。您在 web.config 中拥有它,但没有转换。否则,变换看起来不错。

您需要在此处更改 sqlConnectionString:

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

到 stateConnectionString:

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

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)" />
南巷近海2024-12-19 04:21:10

稍事休息并以新的眼光重新审视之后,我意识到语法实际上很好。

问题是,在某些时候 - 不知道什么时候 - 元素已被移出它所属的元素(可能是我自己或其他团队成员的复制/粘贴错误),所以它只是挂在那里,而不是它应该在的地方曾经是。

一旦我回到它应该在的位置,问题就解决了,转换再次正确地检测到元素并应用转换。

因此,吸取的教训是:如果变换神秘地没有应用于一个元素(当它在另一个元素上运行良好时),请检查以确保该元素位于正确的位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文