2012-04-16 127 views
3

我試圖使用外部配置文件來定義我的web.config文件的根<configuration>節內有多個location元素的一部分。這可能嗎?外部配置文件進行配置部分

我知道如何爲單個部分(例如connectionStrings),但是可以在此爲配置元件內的多個元件來實現這樣做呢? <configuration>;本身不允許configSource屬性。是否有可能創建一個虛擬元素並在configSections中定義它,如果是的話,我會給它一個類型?

背景資料:我想這樣做,這樣我可以定義永久重定向,可能有數百人因此,最好我不想在web.config中本身來定義這一點。即

<configuration> 
    <!-- rest of web.config here --> 
    <!-- i need mutiple location elements so want these in an external file--> 
    <location path="oldpage"> 
    <system.webServer> 
     <httpRedirect enabled="true" destination="/uk/business" httpResponseStatus="Permanent" /> 
    </system.webServer> 
    </location> 
</configuration> 

回答

1

想到我會添加更多的細節。正如CodeMonkey URL Rewrite模塊所暗示的那樣,重寫模塊http://www.iis.net/download/URLRewrite的更多細節。

這些都是我到web.config中做出定義規則和referncing外部文件(在system.webServer)的變化

<rewrite> 
    <rewriteMaps configSource="RewriteMaps.config" />     
    <rules> 
     <rule name="Rewrite rule1 for StaticRewrites"> 
      <match url=".*" /> 
      <conditions> 
       <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" /> 
      </conditions> 
      <action type="Redirect" url="{C:1}" redirectType="Permanent" appendQueryString="false" /> 
     </rule> 
    </rules>   
</rewrite> 

注:還需要更新VS XML Schema來阻止它呻吟這麼多 http://ruslany.net/2010/04/visual-studio-xml-intellisense-for-url-rewrite-2-0/ (請確保你看到這個博客重新註釋爲更新的VS2010 JS)

1

要做到你的要求,你就只需要這樣:

<rewrite> 
    <rules configSource="rewrites.config" /> 
</rewrite> 

任何文件名就足夠了。

你會設置你外在的元素有關的configSource屬性。

+0

謝謝 - 我想我的問題可能會受到嚴重的措辭,這是什麼,我知道該怎麼做的例子,但我不使用重寫部分我想將位置元素添加到配置部分。我會用一個例子更新我的問題。 – deadcrab 2012-04-16 13:10:57