简体   繁体   中英

How to edit and save the connectionstring in web.config file during the installation in c#?

  • i have created installer for the web application.
  • i want to change the default connectionstring value in web.config by the connectionstring passed by the user from the installation.

A simple way might be to simply Read in the web.config and do a string replace, then write out the web.config again:

eg: in web.config containing:

...
<add name="Application" connectionString="SETUP_CONNECTION_STRING" />
...

replace SETUP_CONNECTION_STRING with actual string:

This assumes its done on initial setup where multiple settings could be set without the need to use the Configuration classes etc.

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