对于要部署到的每个环境,您将创建一个转换文件,该文件仅指定原始 Web.config 文件和适用于该环境的已部署 Web.config 文件之间的差异。
Locator 特性所查找的元素执行哪些操作。
customErrors 元素:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
Transform 元素本身不会在部署的 Web.config 文件中重现。
下面各节提供有关要在转换文件中使用的语法的参考信息。
Locator 特性的语法。
条件
选择了与组合 XPath 表达式匹配的元素。
语法
示例
在部署的 Web.config 文件中,所选元素将替换为在转换文件中指定的元素。
<configuration xmlns:xdt="...">
<connectionStrings>
<add name="AWLT" connectionString="newstring"
providerName="newprovider"
xdt:Transform="Replace"
xdt:Locator="Condition(@name='oldname'
or @providerName='oldprovider')" />
</connectionStrings>
</configuration>
Condition 表达式的结果应用于开发 Web.config 文件的有效 XPath 表达式如下所示:
configuration/connectionStrings[@name='AWLT' or @providerName='System.Data.SqlClient']
configuration/connectionStrings) 的隐式 XPath 条件与显式指定的表达式组合起来的结果。
Match
如果指定了多个特性名称,则将仅选择与所有指定特性匹配的元素。
语法
示例
Replace
XPath
Condition 不同,所指定的表达式不追加到与当前元素对应的隐式 XPath 表达式。)
语法
示例
Condition 关键字示例中所选元素相同的元素。
Transform 特性的语法。
Insert
该新元素被添加到任何集合的末尾。
语法
示例
InsertBefore
该 XPath 表达式必须是一个绝对表达式,因为它作为一个整体应用于开发 Web.config 文件,而不只是追加到当前元素的隐式 XPath 表达式中。
语法
示例
InsertAfter
该 XPath 表达式必须是一个绝对表达式,因为它作为一个整体应用于开发 Web.config 文件,而不是追加到当前元素的隐式 XPath 表达式中。
语法
示例
Remove
如果选择了多个元素,则移除第一个元素。
语法
示例
RemoveAll
移除选定的一个或多个元素。
语法
示例
RemoveAttributes
从所选元素移除指定的特性。
语法
示例
SetAttributes
SetAttributes 特性使您能够按原样保留元素而只更改所选特性。
语法
示例
XSLT
Locator 特性来指示其他方面。
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web xdt:Transform="Replace">
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
Transform 特性来将更改应用于子元素。
location 元素的子元素才能进行转换。
<configuration xmlns:xdt="...">
<location path="C:\MySite\Admin" xdt:Locator="Match(path)">
<system.web>
<pages viewStateEncryptionMode="Always"
xdt:Transform="SetAttributes(viewStateEncryptionMode)" />
</system.web>
</location>
</configuration>
Transform 特性,则不会进行任何更改。
|
|
|---|
|
system.web 元素的所有子元素将替换为转换文件中的内容。 |