0

在我的 asp.net 网站中,我在 web.config 中有多个连接字符串。当我在本地服务器上发布进行测试时,我需要选择一个连接字符串,当我需要发布时,我必须在“真实服务器”上发布另一个连接字符串。

<!-- LOCAL SQLEXPRESS -->
<add name="LocalConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TimeLive;Persist Security Info=True;User ID=*********;Password="*********" providerName="System.Data.SqlClient"/>
<!-- IPR-GEST SQLEXPRESS  -->
<add name="ServerReleaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TimeLive;Persist Security Info=True;User ID=*********;Password=*********" providerName="System.Data.SqlClient"/>

由于这两个 connectionString 与用户登录不同,我认为可以将服务器身份验证切换为“Windows 身份验证”,但听起来不太安全。我错了吗?

如何根据我在本地或发布服务器上发布来选择正确的 connectionString?

此外,该解决方案包含一个带有 .dbml 文件的 dll 项目。同样的问题:两个不同的连接字符串,每个服务器一个。有没有一种简单的方法来选择合适的?

4

1 回答 1

1

根据您拥有的 Visual Studio 版本,它具有 Web.config 文件转换,它允许您拥有一个用于开发的配置模板和另一个用于生产的模板。

http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/web-config-transformations

于 2014-06-12T10:22:59.553 回答