[英]How do I use Web.Config transform on my connection strings?
在我当前的项目中,我有一些对本地开发计算机有效的连接字符串:
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=localhost;Initial Catalog=MyDB;Integrated Security=SSPI"
</connectionStrings>
....
</configuration>
我将如何使用Web.Config转换将这一表达式转换为对我们的生产服务器有效的表达式? 生产服务器之一将类似于:
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword"
</connectionStrings>
....
</configuration>
语法对我来说并不明显,我完全无法浏览它的页面 。
这对我有用,但是我有时也觉得它有点苦涩。 您将需要创建另一个名为Web.Config.Release的文件,并将其填充以下内容:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="local" connectionString="Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<appSettings>
<add key="default_db_connection" value="local" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>
您不需要创建新文件,它应该在解决方案资源管理器中,展开Web.config,然后打开Web.Release.config。
斯科特·艾伦(Scott Allan)在此处有一个很好的视频(在“配置和部署”>“配置转换”下)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.