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.
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.
精彩评论