web.config 一些被 IIS 忽略的标记或属性

发布于 2024-11-29 22:06:21 字数 2653 浏览 0 评论 0原文

我正在创建一个系统,其中 web.config 将被动态编辑。原因是,我正在创建一个网站,网站所有者可以在其中创建其他部分,例如 blog 部分,并且我希望系统将相应的重写规则添加到 web.config,使用 XmlReader。

我可以访问重写规则,没有任何问题,但我的问题是,是否有任何特殊标记可以包装自定义生成的规则,或者我可以添加到规则中的特殊属性,这不会改变 IIS 的行为以任何方式,但允许我的代码区分预定义(手写)规则和自动生成的规则。我想要这样的东西:

            <rule name="AHandWrittenRule" stopProcessing="true">
                <match url="^photo/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/PhotoView.aspx?ID={R:1}" />
            </rule>

            <rule name="AnAutoGeneratedRule" AUTOGENERATED="true" stopProcessing="true">
                <match url="^blog/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/BlogView.aspx?ID={R:1}" />
            </rule>

只需注意第二条规则中的 AUTOGENERATED 标记即可。或者另一种选择是:

            <rule name="AHandWrittenRule" stopProcessing="true">
                <match url="^photo/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/PhotoView.aspx?ID={R:1}" />
            </rule>
        <autoGeneratedRules>
            <rule name="AnAutoGeneratedRule" stopProcessing="true">
                <match url="^blog/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/BlogView.aspx?ID={R:1}" />
            </rule>
        </autoGeneratedRules>

这两者中的任何一个都可能吗?因为如果我做不到这一点,我将查看规则的名称并读取/写入特殊前缀或其他一些自定义“标记”,但这是正确的方式,而且似乎对我来说有点老套。

I'm creating a system where web.config will be edited dynamically. The reason for that one is, I'm creating a website where site owner may create additional sections, such as a blog section, and I want the system to add the corresponding rewrite rule to web.config, using an XmlReader.

I can access the rewrite rules, no problems with that one, but my question is that, is there any special tag I can wrap custom generated rules, or a special attribute that I can add to the rules, that will not change IIS' behavior in any way, but allow my code to distinguish between predefined (hand written) rules and auto-generated rules. I want something like this:

            <rule name="AHandWrittenRule" stopProcessing="true">
                <match url="^photo/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/PhotoView.aspx?ID={R:1}" />
            </rule>

            <rule name="AnAutoGeneratedRule" AUTOGENERATED="true" stopProcessing="true">
                <match url="^blog/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/BlogView.aspx?ID={R:1}" />
            </rule>

Just notice that AUTOGENERATED tag in the second rule. Or another option is this:

            <rule name="AHandWrittenRule" stopProcessing="true">
                <match url="^photo/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/PhotoView.aspx?ID={R:1}" />
            </rule>
        <autoGeneratedRules>
            <rule name="AnAutoGeneratedRule" stopProcessing="true">
                <match url="^blog/([^/]+)/?$" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="/BlogView.aspx?ID={R:1}" />
            </rule>
        </autoGeneratedRules>

Is any of those two possible? Because if I can't do that I'll be looking at the names of the rules and read/write a special prefix or some other custom "marker", but it's the the right way and seems a little hacky to me.

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

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

发布评论

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

评论(1

要走干脆点 2024-12-06 22:06:21

我最终用不同的方法实现了我想要的目标,而没有触及 web.config。

显然,web.config 对于未识别的标签和属性过于严格(无论如何都应该是这样)。

I've ended up achieving what I wanted with a different approach, without touching web.config.

Apparently, web.config is too strict (it should be this way anyway) about unidentified tags and attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文