[英]web.config Multiple config sources
I need to declare multiple config sources for rewrite url's as the list of rewrites is very lengthy (+10000 rewrites). 我需要声明多个配置源来重写url,因为重写列表很长(+10000次重写)。
This doesn't work : 这不起作用:
<rewrite>
<rules configSource="App_Config\Rewrite\UrlRewrites1.config"></rules>
<rules configSource="App_Config\Rewrite\UrlRewrites2.config"></rules>
</rewrite>
</system.webServer>
With the following exception: 除了以下例外:
Config section 'system.webServer/rewrite/rules' already defined.
配置部分“ system.webServer / rewrite / rules”已经定义。 Sections must only appear once per config file.
每个配置文件中的节只能出现一次。
The "configSource" supports only one config file, so you can't have multiple config files by default. “ configSource”仅支持一个配置文件,因此默认情况下不能有多个配置文件。 This goes alose for the node in the web.config.
这对于web.config中的节点是可行的。
I suggest you try to do it programmatically You can use ServerManager class to get access to website configuration. 我建议您尝试以编程方式进行操作。您可以使用ServerManager类来访问网站配置。 You will probably need to add a reference to Microsoft.Web.Administration.
您可能需要添加对Microsoft.Web.Administration的引用。 Read your config files and add each rule mannually.
阅读您的配置文件并手动添加每个规则。
Something like this: 像这样:
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetWebConfiguration("Default Web Site");
ConfigurationSection rulesSection = config.GetSection("system.webServer/rewrite/rules");
ConfigurationElementCollection rulesCollection = rulesSection.GetCollection();
ConfigurationElement ruleElement = rulesCollection.CreateElement("rule");
ruleElement["name"] = @"rule";
ConfigurationElement matchElement = ruleElement.GetChildElement("match");
matchElement["url"] = @"foo\.htm";
ConfigurationElement actionElement = ruleElement.GetChildElement("action");
actionElement["type"] = @"Rewrite";
actionElement["url"] = @"bar.htm";
rulesCollection.Add(ruleElement);
serverManager.CommitChanges();
} }
There is also another option but I haven't tried it myself. 还有另一种选择,但我自己还没有尝试过。 You can write your own custom rewrite provider for url rewrite module.
您可以为URL重写模块编写自己的自定义重写提供程序。 Here is a walkthrough how to do it: Custom Rewrite Provider Walkthrough
这是一个演练方法: 自定义重写提供者演练
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.