11

我对此很困惑。我想在开发时使用桌面上的 SQL Server,并在发布项目时使用实时 SQL Server。我正在使用 Visual Studio 2010 中的转换内容。

当我尝试发布我的项目时,我得到“匹配定位器不存在属性‘名称’”。

我的 Web.config 文件包含:

<connectionStrings>
    <add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" providerName="System.Data.SqlClient"/>
</connectionStrings>

<system.web>
    <sessionState mode="SQLServer" sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=eGov" timeout="20" allowCustomSqlDatabase="true" />
</system.web>

我仍在测试它,所以现在,我的 Web.Release.config 文件包含:

<connectionStrings>
    <add name="EFDbContext"
        connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" 
            providerName="System.Data.SqlClient" 
            xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>

<system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <sessionState mode="SQLServer"
        sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
        timeout="20" allowCustomSqlDatabase="true"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</system.web>

我在网上看到的任何东西只会让我更加困惑。任何帮助让我启动并运行?

4

3 回答 3

16

xdt:Locator="Match(name)意味着系统将匹配节点以使用名称标签替换。如果你没有name属性,那么它会失败。您必须有一些独特的属性才能使用这种类型的转换。

于 2012-08-24T01:38:56.910 回答
11

嗬!问题出在该sessionState部分。它应该是:

<system.web>
    <sessionState mode="SQLServer"
        sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
        timeout="20" allowCustomSqlDatabase="true"
        xdt:Transform="SetAttributes" xdt:Locator="XPath(configuration/system.web/sessionState)" />
</system.web>
于 2011-11-03T16:36:49.343 回答
5

在 Match(name) 中使用“name”用于典型的配置设置,如下所示。在这种情况下,关键是“名称”。

<add name="errorAddress" email="me@google.com" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />

如果您的设置中的关键是其他东西,那就是您需要使用的:

<add token="UserToken" value="23jkl2klk2j3kja9d8f" xdt:Transform="SetAttributes" xdt:Locator="Match(token)"/>
于 2016-08-03T22:08:25.787 回答