IIS 7 URL重写模块web.config部分c#

时间:2011-10-14 18:17:13

标签: iis-7 config

我们正在使用带有asp.net C#的IIS7 URL重写模块,所有的URL都被配置并直接写入web.config:

<system.webServer>
    <!-- ... -->
    <rewrite>
        <rules>
            <clear />
            <rule name="Category URL" stopProcessing="true">
                <match url="somepage.aspx" ignoreCase="false"/>
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{QUERY_STRING}" pattern="REDIRECTION=true"
                         ignoreCase="false"/>
                    <add input="{QUERY_STRING}" pattern="categoryid=([^&amp;]*)"/>
                </conditions>
                <action type="Redirect" url="http://{HTTP_HOST}/browsing/categorylanding.aspx?navcategoryid={C:1}"/>
            </rule>
        </rules>
    </rewrite>
 </system.webServer>

我需要将其移到一个部分,以便我可以为QA,DEV和Production制定单独的规则,我将在该部分中定义的类型是什么?

<configSections>
    <section name="IISURLRewriteSection" type="???"/>
</configSections>

一旦从web.config移到另一个自定义配置文件,IIS会自动获取这些设置吗?

2 个答案:

答案 0 :(得分:0)

从调试的角度来看,我们编写了自己的HTTPModule,以及IIS级别出现的任何问题都必须让运营团队参与进来 - 只需遵循我们组织中定义的流程:)

答案 1 :(得分:0)

最好的解决方案imho是将配置详细信息移动到外部文件中,然后可以根据环境进行交换。

使用Moving IIS7 url rewrite section out of the web.config file中描述的方法很容易做到这一点,您可以在Web.config文件中找到类似的内容:

<system.webServer>
    <rewrite configSource="rewrite.config"/>
</system.webServer>

然后,您可以将特定于环境的内容存储在单独的文件rewrite.config中,如下所示:

<rewrite>
    <rules>
        <clear />
        <rule name="Category URL" stopProcessing="true">
            <!-- ... --->
        </rule>
    </rules>
</rewrite>