2012-04-16 131 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