【发布时间】:2015-10-24 05:22:23
【问题描述】:
我在 c# 中开发了一个应用程序,asp.net web 应用程序(仅在我们公司内部使用),最后我将应用程序部署在为此目的分配的服务器 PC(不同的主机和端口)中。
当我在我的 PC 中开发或维护应用程序时,具有不同的主机和端口,每次我需要发布我更改 web.config 中的连接字符串并复制服务器 PC 中的应用程序文件夹时,interpub->wwwroot。
是否有任何选项可以避免每次更改?即,对于发布,我将使用单独的 web.config,而对于开发工作,我将使用单独的 web.config。
服务器PC-web.config,连接字符串:
<connectionStrings>
<add name="MySqlConnectionString" connectionString="server=192.168.3.5;user id=root;password=sim;database=simpayroll;allowuservariables=True;port=3306"
providerName="MySql.Data.MySqlClient" />
<add name="simpayrollConnectionString" connectionString="server=192.168.3.5;user id=root;port=3306;password=sim;database=simpayroll;persistsecurityinfo=True;allowuservariables=True"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
我的本地 Web.config
<connectionStrings>
<add name="MySqlConnectionString" connectionString="server=localhost;user id=root;password=root;database=simpayroll;allowuservariables=True;port=3306"
providerName="MySql.Data.MySqlClient" />
<add name="simpayrollConnectionString" connectionString="server=localhost;user id=root;port=3306;password=root;database=simpayroll;persistsecurityinfo=True;allowuservariables=True"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>
【问题讨论】:
-
如果凭据像密码一样重要,请隐藏它们
-
@utility 我怀疑 OP 询问的是 web.config transformations on publishing 而不是多个配置文件。
-
@AlexeiLevenkov 是的,我认为 OP 需要有多个配置,因为我不清楚只是放入 cmets :)