简体   繁体   中英

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.

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.

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.

Server PC- web.config, connection string:

  <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

  <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

In your Web.Release.Config file,

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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