【问题标题】:Why am I getting a "No attribute 'name' exists for the Match Locator" error when publishing?为什么我在发布时收到“匹配定位器不存在属性‘名称’”错误?
【发布时间】:2011-12-21 07:42:21
【问题描述】:

我对此感到很困惑。我想在开发时使用桌面上的 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>

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

【问题讨论】:

    标签: visual-studio-2010 web-config-transform


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      哇!问题出在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>
      

      【讨论】:

        【解决方案3】:

        在 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)"/>
        

        【讨论】:

          猜你喜欢
          • 2019-03-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-08-27
          • 2013-03-09
          • 1970-01-01
          • 2015-01-03
          相关资源
          最近更新 更多