开发者

Is it possible to place URL Rewrite configuration in a separate config file?

We are using URL Rewrite in an ASP.NET website hosted on IIS7:

http://www.iis.net/download/URLRewrite

This is OK, but business users have to request IT to update the w开发者_如何学编程eb.config file whenever a new redirect is required.

Is it possible to put all URL rewrite configurations in a separate config file, which could be managed by business users, without letting them edit ANY other settings?

The goal is to let business users customize rewrites without needed to go through IT.

(for this question, please assume that adding new rewrites on-demand is a business requirement)


Yes. Any config section can be external to the web/app.config. You create an empty element and give it a configSource attribute whose value is the path to the external configfile, thus:

<connectionStrings configSource="ConnectionStrings.config"/>

The referenced file has as its root element the config section:

<?xml version="1.0"?>
<connectionStrings>
  <add name="MyDB" connectionString="Data Source=myServerAddress;Initial Catalog=MyDataBase;Integrated Security=SSPI;"/>
</connectionStrings>

That's about it. Changes made to the external config file for a ASP.Net app will trigger application reset, just as if you tweaked the web.config.

More at

  • http://weblogs.asp.net/fmarguerie/archive/2007/04/26/using-configsource-to-split-configuration-files.aspx
  • http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx

Another option is to use the ConfigurationManager class to load and read a custom config file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜