Is it possible to override both appSettings and connectionStrings in a Local.config file?

佐手、 提交于 2019-12-31 03:59:47

问题


We presently override appSettings from our web.config in a Local.config file for each developer. However we also need to override connection strings, so we access our local copy on our machine while the web.config might reference the production server. I know that you can override appSettings by specifying file="Local.config", but is this possible for the connectionStrings as well? We already make use of an external file for the connection strings but this file has all three connection strings (local developer, dev, and production).

What I'd like to do is have the connectionString defaulted to production, but overridden on a developer's machine and on the development server. However, this doesn't seem to be possible as unlike appSettings, you can't specify a value for connectionStrings when you tell it to use an external file.

Is this possible to achieve without having to add additional code?

I should note that I cannot use the Config Transformations at the moment as we are on ASP.NET 3.5.


回答1:


In the main application configuration file, you use the configSource attribute to specify the fully qualified name and location of the external file. This example refers to an external configuration file named connections.config.

<?xml version='1.0' encoding='utf-8'?>
<configuration>
    <connectionStrings configSource="connections.config"/>
</configuration>

For detailed information, please visit this link on msdn (section: Using External Configuration Files)



来源:https://stackoverflow.com/questions/11121135/is-it-possible-to-override-both-appsettings-and-connectionstrings-in-a-local-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!