0
我一直在尝试谷歌和改变,现在恨这种模式,请帮助我。如何管理不同的web.x.config文件
我有一个web.config看起来像这样:
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
在我web.Debug.config:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ApplicationServices"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
我然后运行 “调试”,并希望访问配置在web.Debug.config而不是web.config。但它总是返回web.config,我做错了什么? 程序来检索的代码如下:。
ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString
嗯..我有点讨厌,这使得它非常恼人的工作,这是第一次,需要diploy每次我想看看我正在做的工作,但谢谢反正! 我试过了,但得到这个错误,任何线索? 条目'ApplicationServices'已被添加。 – MatiasP
@MatiasP:我同意你的意见;不是很直接,特别是如果有一个名为“web.Debug.config”的文件。但一旦你习惯了它,转换是一个强大的工具。错误的原因很可能是连接字符串重新添加。如果条件设置不当,这可能与转换有关。一个好的起点是首先检查web.config连接字符串是否只包含一次。然后运行转换并检查输出连接字符串是否包含两次。 – Markus