简体   繁体   English

IIS7重写模块规则的备用Web.Config

[英]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: 然后在external.config文件中添加您的规则:

<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 你必须与整个RewriteMap指令S部件要做到这一点:根据该论坛的帖子,你不能用RewriteMap指令做到这一点: http://forums.iis.net/t/1154113.aspx

This works for me in web.config: 这在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. 一个很酷的事情是,当您编辑规则并将更改写回外部文件时, IIS配置编辑器会尊重此外部文件。

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: 它不起作用,你得到HTTP错误500.19内部服务器错误:

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? 任何人都可以指向rewrite元素和configSource属性的configSource MSDN帮助页面? The MSDN article on system.webServer does not mention the rewrite element and I can't find an MSDN page via google. 关于system.webServerMSDN文章没有提到重写元素,我无法通过谷歌找到MSDN页面。

I found configuration documentation but it doesn't seem to cover use of the configSource attribute. 我找到了配置文档,但它似乎没有涵盖configSource属性的使用。

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. 我的猜测是<rules />元素是作为具有configSource属性的SectionInformation实现的,而<rewrite />元素是没有的ConfigurationSection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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