【问题标题】:IIS 7 URL rewrite module web.config section c#IIS 7 URL 重写模块 web.config 部分 c#
【发布时间】:2011-10-14 18:17:12
【问题描述】:

我们使用 IIS7 URL 重写模块和 asp.net C#,所有的 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 和生产制定单独的规则,我将在该部分中定义的“类型”是什么?

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

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

【问题讨论】:

  • 似乎没有人真正回答这个问题

标签: iis-7 config


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    恕我直言,最好的解决方案是将配置详细信息移动到外部文件中,然后您可以根据环境换出这些文件。

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

    【讨论】:

      猜你喜欢
      • 2013-04-23
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2011-10-29
      • 2011-05-23
      • 2011-01-14
      • 2013-05-19
      相关资源
      最近更新 更多