简体   繁体   中英

Alternate Web.Config for IIS7 Rewrite Module Rules

是否可以将IIS7重写模块创建的规则从根网站配置移动到自己的Web配置文件中,就像使用appsettings一样,如果是这样的话?

I can't seem to get it working, but the way it's described is:

<rewrite>
   <rewriteMaps configSource="external.config">
   </rewriteMaps>
</rewrite>

Then in the external.config file add your rules:

<rewriteMaps>
  <rewriteMap ...
  ...
</rewriteMaps>

You have to do this with the entire rewriteMap s section: according to this forum post, you can't do this with the rewriteMap: http://forums.iis.net/t/1154113.aspx

This works for me in web.config:

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

One cool thing is that the IIS Configuration Editor respects this external file when you edit the rules and writes the changes back to the external file.

If you put:

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

it won't work, you get HTTP error 500.19 Internal server error:

Error Code:   0x8007000d
Config Error: Unrecognized attribute 'configSource'

Can anyone point to the definitive MSDN help page on the rewrite element and the configSource attribute? The MSDN article on system.webServer does not mention the rewrite element and I can't find an MSDN page via google.

I found configuration documentation but it doesn't seem to cover use of the configSource attribute.

My guess is that the <rules /> element is implemented as a SectionInformation which has a configSource property while the <rewrite /> element is a ConfigurationSection which does not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM