在部署期间更改 web.config

发布于 2025-01-08 04:28:04 字数 1646 浏览 0 评论 0原文

我需要在开发和部署期间在http和https之间切换。

为此,我需要在 web.config 中进行以下更改:

 <behaviors>
  <serviceBehaviors>
    <behavior name="DirectInstallHelperServiceBehavior">
      <!-- need to change to <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"> -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false">
      </serviceMetadata>
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <webHttpBinding>
    <binding>
<!-- need to add the following, but don't know how
      <security mode="Transport">
        <transport clientCredentialType="Basic"/>
      </security>
-->
    </binding>
  </webHttpBinding>
</bindings>

因此,我尝试在 Web.Release.config 中添加以下行:

<behaviors>
  <serviceBehaviors>
    <behavior name="DirectInstallHelperServiceBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" xdt:Transform="setAttribute(httpsGetEnabled, httpGetEnabled)" xdt:Locator="Match(name)"></serviceMetadata>
    </behavior>
  </serviceBehaviors>
</behaviors>

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

但我做错了,因为当我将服务发布到文件系统时,我仍然看到web.config 的开发 http 版本。 任何帮助表示赞赏。

I need to switch between http and https during development and deployment.

To do that, I need to make the following changes in web.config:

 <behaviors>
  <serviceBehaviors>
    <behavior name="DirectInstallHelperServiceBehavior">
      <!-- need to change to <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"> -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false">
      </serviceMetadata>
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <webHttpBinding>
    <binding>
<!-- need to add the following, but don't know how
      <security mode="Transport">
        <transport clientCredentialType="Basic"/>
      </security>
-->
    </binding>
  </webHttpBinding>
</bindings>

So I try to add the following lines in Web.Release.config:

<behaviors>
  <serviceBehaviors>
    <behavior name="DirectInstallHelperServiceBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" xdt:Transform="setAttribute(httpsGetEnabled, httpGetEnabled)" xdt:Locator="Match(name)"></serviceMetadata>
    </behavior>
  </serviceBehaviors>
</behaviors>

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

But I am doing it wrong because when I publish the service to my filesystem, I still see the development http version of web.config.
Any help is appreciated.

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

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

发布评论

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

评论(1

划一舟意中人 2025-01-15 04:28:04

xdt:Transform 值更改为 SetAttributes。并删除 xdt:Locator 因为没有 name 属性。

<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" xdt:Transform="SetAttributes"></serviceMetadata>

Change your xdt:Transform value to SetAttributes. And remove xdt:Locator since there is no name attribute.

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