【问题标题】:Add web.release.config value at compilation在编译时添加 web.release.config 值
【发布时间】:2019-03-01 09:52:20
【问题描述】:

当有发布编译时,我需要将此块添加到我的 web.config 中的绑定中:

<security mode="Transport">
  <transport clientCredentialType="None"/>
</security>

这是我的 web.config 的 sn-p :

<bindings>
  <basicHttpBinding>
    <binding name="BasicBinding" closeTimeout="24.20:31:23.6470000" openTimeout="24.20:31:23.6470000" receiveTimeout="24.20:31:23.6470000" sendTimeout="24.20:31:23.6470000" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>

这是我在documentation之后的转换方法web.release.config:

<bindings>
<basicHttpBinding>
  <binding>
    <security mode="Transport" xdt:Transform="InsertAfter(/configuration/system.serviceModel/bindings/basicHttpBinding/binding)">
      <transport clientCredentialType="None"/>
    </security>
  </binding>
</basicHttpBinding>
</bindings>

我在 VSTS 上编译时遇到以下错误:

[error]Sources\Foo.Interface\Web.Release.config(16,6):错误:源文档中没有元素匹配'/configuration/bindings/basicHttpBinding'

当然,我尝试过使用其他类似的值,但始终面临同样的问题。

【问题讨论】:

    标签: c# .net wcf


    【解决方案1】:

    不清楚错误。但是如果你想在 web.config 的绑定节点中插入安全节点,你可以在 web.release.config 中编写以下代码 使用 xdt:Transform="Insert"

      <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicBinding" >
          <security mode="Transport"  xdt:Transform="Insert" >
            <transport clientCredentialType="None"/>
          </security>
    
        </binding>
      </basicHttpBinding>
    </bindings>
    

    【讨论】:

    • 有效!我不知道它是否相关,但我忘了在替换路径中添加system.serviceModel。谢谢大家
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    相关资源
    最近更新 更多