简体   繁体   English

在ASP.NET IIS服务器中发布后编辑Web.Config

[英]Edit Web.Config after publishing in asp.net IIS server

I have a developed a application in c#,asp.net web application(using only inside our company) and finally am deploying the application in server PC (different host and port )allocated for this purpose. 我已经在c#,asp.net Web应用程序中开发了一个应用程序(仅在我们公司内部使用),最后将应用程序部署在为此目的分配的服务器PC(不同的主机和端口)中。

When i developing or maintaining the application in my PC, having different host and port, every time when i need to publish im changing the connection string in web.config and and copying app folder in server PCs, interpub->wwwroot. 当我在具有不同主机和端口的PC中开发或维护应用程序时,每次需要发布im更改web.config中的连接字符串并在服务器PC中复制app文件夹时,interpub-> wwwroot。

Is there any option to avoid each time changes? 有什么选择可以避免每次更改? ie, for publishing i will use seperate web.config and for developing work i use seperate web.config. 即,对于发布,我将使用单独的web.config,对于开发工作,我将使用单独的web.config。

Server PC- web.config, connection string: 服务器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>

My local Web.config 我的本地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>

You can use web.config transformations to over come with your problem 您可以使用web.config转换来解决问题

In your Web.Release.Config file, 在您的Web.Release.Config文件中,

<connectionStrings xdt:transform="Replace"> <add name="MySqlConnectionString" connectionString="your connection string" providerName="MySql.Data.MySqlClient" /> <add name="simpayrollConnectionString" connectionString="your connection string" providerName="MySql.Data.MySqlClient" /> </connectionStrings>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM