2012-08-08 16 views
37

Mam pewne reguły przepisywania IIS, które chcę zmienić w zależności od środowiska. Reguły przepisywania rozwój są w pliku web.config, potem na końcu pliku web.test.config mam:Zastępowanie reguł przepisywania IIS w transformacji web.config

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

Moje ustawienia aplikacji są coraz przekształconej gdy wdrożyć do testowania, ale przez IIS przepisanie zasady nie są. Miałem nadzieję, że cała sekcja <rewrite> zostanie po prostu zastąpiona przez tę w pliku transformacji (jak na http://msdn.microsoft.com/en-us/library/dd465326.aspx), ale nic się nie zmienia.

Próbowałem oddanie xdt:Transform="Replace" xdt:Locator="Match(name)"> na indywidualnych zasadach TOO:

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

Ale znowu to nie robi różnicy.

Czy można nawet zastąpić reguły przepisywania w web.config, a jeśli tak, to czego mi brakuje?

Odpowiedz

0

Możliwe jest przekształcenie sekcji przepisywania na system.webServer. Początkowo miałem ten sam problem i zdałem sobie sprawę, że przypadkowo umieściłem niepoprawnie węzeł do przepisywania w system.web. Chociaż nie wygląda to na Twój problem na podstawie podanego fragmentu, podejrzewam, że Twój problem jest związany z umieszczaniem węzła w pliku transformacji.

Oto co mój Web.Debug.config wygląda (i ta wersja jest pisanie poprawnego Web.config na kompilacji debugowania):

<?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

Ponieważ nie miał żadnych reguł przepisywania w moim main web.config, transformacja Zamień nie działa. I z powodzeniem stosowany Wstaw przekształcać, jak poniżej:

<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

Sztuczka używam to dać Akcja nazwę
następnie w moim transformaty tylko dodać xdt:Transform="SetAttributes" xdt:Locator="Match(name)" jak na poniższym

<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> 

Powyższy przykład jest aby dodać www do wszystkich żądań

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

właśnie aktualizacja dodanie nazwy do działania nie będzie działać jak chciał więc uaktualniony kod w poniższym

<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

Sekcja przepisać pracował dziwnie mi się w pierwszej chwili podczas tworzenia configs wydaniu, błędy i sekcje nie pokazuje w ogóle. Tak to rozwiązałem.

Microsoft (R) Budowanie wersja silnika 12.0.31101.0

Microsoft .NET Framework w wersji 4.0.30319.0

Edit Po ingerować w to zdałem sobie sprawę, że posiadanie tag przepisywania na serwerze, który nie ma wtyczki do przepisywania, serwer internetowy zwraca błąd.I wa różne konfiguracje na serwerze i komputerze lokalnym Developmen więc poprawka jest:

tylko Un przekształconych web.config potrzebuje tag aw web.config.release za podstawowy kanoniczna nazwa hosta reguły

<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> 

akcja nie potrzebuje w ogóle, ale nazwę znacznika przepisywania potrzebuje XDT: Transform = „Wstaw”

Oczywiście jeśli chcesz go na lokalnym aswell maszynowego, musiałby aktualizacji zamiast.

Powiązane problemy