web.config 一些被 IIS 忽略的标记或属性
我正在创建一个系统,其中 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 name
s 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终用不同的方法实现了我想要的目标,而没有触及 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.