45

すべてのトラフィックをhttpsに移動するように指定されたweb.config書き換えルールがあります。ルールは機能しますが、デバッグ中にSSLが必要になることはありません。公開で機能するweb.release.config変換がすでに実行されているので、そこに書き換えルールを設定することにしました。問題は、書き換えルールが他の設定のように変換されていないことです。web.configの設定は次のとおりです。

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>

    <rewrite></rewrite>
</system.webServer>

そして、これが行われている変換です:

  <system.webServer>
<rewrite>
  <rules>
    <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
      <match url="(.*)"/>
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$"/>
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
    </rule>
  </rules>
</rewrite></system.webServer>

書き換えルールをweb.configにコピーするだけで、正常に機能します。web.Release.configトランスフォームがこのセクションだけで機能しない理由を知っている人はいますか?

4

4 に答える 4

45

xdt変換は、変換する必要のある要素に適切な属性を設定した場合にのみ発生します。xdt:Transformリリース構成に属性を追加してみてください。

<system.webServer xdt:Transform="Replace">
    <!-- the rest of your element goes here -->
</system.webServer>

system.webServerこれにより、からの要素全体をからの要素Web.configに置き換える必要があることが変換エンジンに通知されWeb.Release.configます。

xdt変換エンジンは、属性を持たない要素を黙って無視します。

MSDNへの必須リンク。

于 2011-08-10T22:58:10.317 に答える
33

もう1つの方法は、ローカルホストを使用している場合に無効になる書き換え条件を設定することです。

<conditions>
    <add input="{HTTP_HOST}" pattern="localhost" negate="true"/>
</conditions>
于 2011-08-21T07:41:53.397 に答える
10
<system.webServer>
    <rewrite>
        <rules xdt:Transform="Replace">
            <clear />
            <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_HOST}" pattern="localhost(:\d+)?" negate="true" />
                <add input="{HTTP_HOST}" pattern="127\.0\.0\.1(:\d+)?" negate="true" />
                <add input="{HTTPS}" pattern="OFF" />
              </conditions>
              <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
            </rule>
        </rules>          
    </rewrite>
</system.webServer>
于 2015-06-22T19:27:36.807 に答える
2

ここで他の答えを要約すると、明らかなことがわかりました。「置換」はノードを置き換えるだけで、「挿入」はしません(正しいトラックを提供してくれたDigitalDに感謝します)。残りの変換ファイルはreplaceを使用するため、ベースweb.config(変換されるタグ)で空のタグを選択しました。

<system.webServer>
...other tags here that do not get transformed...
<rewrite />
</system.webServer>

理想的には、挿入または置換(または削除して挿入)する「上書き」があります。

于 2013-09-10T20:18:33.853 に答える