2012-08-08 25 views
37

私は、環境によって異なるIIS書き換えルールをいくつか持っています。開発の書き換えルールは、web.configファイルで、その後、私が持っているweb.test.configファイルの末尾にされていますweb.config変換でIIS書き換えルールを置き換える

<appSettings> 
     ...Some app settings tranforms here 
    </appSettings> 
    <system.webserver> 
      <rewrite xdt:Transform="Replace"> 
       <rules> 
       ... rules here 
       </rules> 
      </rewrite> 
      </system.webserver> 
     </configuration> 

マイアプリの設定は、私がテストするために展開するときに変換しますが、IISの書き換えによって取得されていますルールはそうではありません。 <rewrite>セクション全体が(http://msdn.microsoft.com/en-us/library/dd465326.aspxのように)変換ファイル内のセクションで置き換えられるだけで、何も変化しないことを期待していました。

<rule name="Test rule" stopProcessing="true" xdt:Transform="Replace" xdt:Locator="Match(name)"> 

をしかし、再び、これは違いはありません:

私はあまりにも、個々のルールにxdt:Transform="Replace" xdt:Locator="Match(name)">を入れて試してみました。

web.configの書き換えルールを置き換えることも可能ですか?もしそうなら、何が欠けていますか?

答えて

0

system.webServerの書き換えセクションを変換することは可能です。私は当初は同じ問題を抱えていて、誤ってsystem.webの下に書き換えノードを誤って配置してしまったことに気付きました。これは、あなたが提供したスニペットに基づいてあなたの問題のようには見えませんが、私はあなたの問題が変換ファイルのノードの配置に関係しているかどうか疑いがあります。ここで

は私Web.Debug.configは、次のようになります(このバージョンでは、デバッグビルドで正しいのWeb.configを書いている):

<?xml version="1.0"?> 

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> 

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <!-- 
    In the example below, the "SetAttributes" transform will change the value of 
    "connectionString" to use "ReleaseSQLServer" only when the "Match" locator 
    finds an atrribute "name" that has a value of "MyDB". 

    <connectionStrings> 
     <add name="MyDB" 
     connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> 
    </connectionStrings> 
    --> 
    <system.web> 
    <!-- 
     In the example below, the "Replace" transform will replace the entire 
     <customErrors> section of your web.config file. 
     Note that because there is only one customErrors section under the 
     <system.web> node, there is no need to use the "xdt:Locator" attribute. 

     <customErrors defaultRedirect="GenericError.htm" 
     mode="RemoteOnly" xdt:Transform="Replace"> 
     <error statusCode="500" redirect="InternalError.htm"/> 
     </customErrors> 
    --> 
    </system.web> 
    <system.webServer> 
    <rewrite xdt:Transform="Replace"> 
     <rules> 
     <clear/> 
     <rule name="Canonical Hostname"> 
      <!-- Note that I have stripped out the actual content of my rules for the purposes of posting here... --> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 
38

私は私の中に任意の書き換えルールを持っていなかったようメインのweb.configでは、置換の変換が機能しませんでした。私が使用してのトリックは、アクションに名前
を与えている

<system.webServer> 
<rewrite xdt:Transform="Insert"> 
    <rules> 
    <rule name="CanonicalHostNameRule1"> 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="^www\.mysite\.com$" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="http://www.mysite.com/{R:1}" /> 
    </rule> 
    </rules> 
</rewrite> 
</system.webServer> 
0

その後、私の転換にちょうど上記の例である以下の

<system.webServer> 
<rewrite> 
    <rules> 

    <rule name="RedirecttoWWW" enabled="true" > 
     <match url="(.*)" /> 
     <conditions> 
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
     </conditions> 
     <action name="AddWWW" type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" /> 
    </rule> 

    </rules> 
</rewrite> 

ようxdt:Transform="SetAttributes" xdt:Locator="Match(name)"を追加します。以下のように私は成功し、挿入変換に使用しましたすべての要求にWWWを追加し

------- UPDATE -----

アクションに名前を追加するだけで、更新はので、私が表示されていないリリースのconfigs、エラーやセクションを作成するときに書き換えセクションでは、最初に私に変なふうに働い次

<system.webServer> 

     <rule name="RedirecttoWWW" enabled="true" xdt:Transform="RemoveAll" xdt:Locator="Match(name)" > 
     </rule> 
     <rule name="RedirecttoWWW" enabled="true" xdt:Transform="InsertIfMissing" xdt:Locator="Match(name)" > 
     <match url="(.*)" /> 
     <conditions> 
      <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" /> 
     </conditions> 
     <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" /> 
     </rule> 
    </rules> 
    </rewrite> 
    </system.webServer> 
6

ように、コードを更新したかったように動作しません。まったく。これは私がそれを解決した方法です。

のMicrosoft(R)エンジンのバージョン12.0.31101.0

は、Microsoft .NET Frameworkを構築し、バージョン4.0.30319.0

編集はこれでふざける後、私は書き換えタグを持つことに気づきました再書き込みプラグインを持たないサーバーでは、Webサーバーでエラーが返されます。

が非変換web.configファイルはタグのみを必要とし、基本的な正規のホスト名ルール

ためweb.config.releaseで:修正プログラムがあるので、私は、サーバーとローカルdevelopmenマシン上の異なる構成をwan't
<configuration> 
<system.webServer> 
     <rewrite xdt:Transform="Insert"> 
      <rules> 
       <rule name="CanonicalHostNameRule" xdt:Transform="Insert"> 
        <match url="(.*)" /> 
        <conditions> 
         <add input="{HTTP_HOST}" pattern="^www\.host\.com$" negate="true" /> 
        </conditions> 
        <action type="Redirect" url="http://www.host.com/{R:1}" /> 
       </rule> 
      </rules> 
     </rewrite> 
</system.webServer> 
</configuration> 

アクションが書き換えタグが、すべての名前を必要としませんでしたがXDTを必要とする:あなたは、ローカルマシンのaswellにそれをしたい場合は明らかに

を「挿入」=トランスフォーム、それが代わりに更新が必要になります。