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

发布于 2024-12-10 02:51:21 字数 1250 浏览 0 评论 0原文

我们正在使用带有 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 会自动选择这些设置吗?

We are using IIS7 URL rewrite module with asp.net C#, all of the URLs are configured and written directly into 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=([^&]*)"/>
                </conditions>
                <action type="Redirect" url="http://{HTTP_HOST}/browsing/categorylanding.aspx?navcategoryid={C:1}"/>
            </rule>
        </rules>
    </rewrite>
 </system.webServer>

I need to move this to a section so that I can have seperate rules for QA, DEV and Production, what would be the "type that i would define in the section?

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

Will the IIS automatically pick up these settings once moved outside from web.config to another custom config file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简单爱 2024-12-17 02:51:21

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

We resorted to writing our own HTTPModule since from debugging point of view as well any issues that would arise at IIS level would have to have the Operations team involved - just following a process defined in our org :)

2024-12-17 02:51:21

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

使用将 IIS7 url 重写部分移出 web.config 文件中描述的方法非常容易,您可以在其中在您的 Web.config 文件中会有类似这样的内容:

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

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

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

The best solution, imho, would be to move the configuration details into external files, which you can then swap out per-environment.

This is pretty easy to do using the method described in Moving IIS7 url rewrite section out of the web.config file, where you would have something like this in your Web.config file:

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

Then you can store the environment specific stuff in a separate file, rewrite.config, looking something like this:

<rewrite>
    <rules>
        <clear />
        <rule name="Category URL" stopProcessing="true">
            <!-- ... --->
        </rule>
    </rules>
</rewrite>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文