简体   繁体   中英

IIS 7 rewrite module, is it possible to programatically define the rewriting rules rather than manage them in the Web.Config?

I'm working on a bespoke CMS system for which each of our customers have their own domain name through which they access our their content on our system. For this we are using the IIS rewrite module to ensure that each domain points to the content which each customer owns.

An example of our rewrite rule is as follows,

    <rule name="ReverseProxyInboundRuleCustomerX" enabled="true" stopProcessing="true">
      <match url=".*" negate="false" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www.)?customerx.com" />
        <add input="{REQUEST_URI}" pattern="/Public/([A-Z][a-z].+)" negate="true" />
        <add input="{REQUEST_URI}" pattern="/combres.axd/([A-Z][a-z].+)" negate="true" />
        <add input="{REQUEST_URI}" pattern="/Community/([1-9][0-9])/([A-Z][a-z].+)" negate="true" />
        <add input="{REQUEST_URI}" pattern="/fbchannel.ashx" negate="true" />
      </conditions>
      <action type="Rewrite" url="/Community/10/{R:0}" />
    </rule>

What I would like to do is to dynamically and programatically define these rules via code in my ASP MVC project rather than rely on the web.config which requires someone go in and tinker with the production server each time we need to set up a new customer.

I don't wan't to dynamically modify the web.config, I would prefer to remove the responsibility of managing these rules from the web.config all together.

Is it possible to dynamically declare these rules in code?

What your looking to do could be easily implemented in a custom rewrite provider. We have had great success using them for large content migration projects where simple pattern based rewriting was not an option.

http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module

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