简体   繁体   中英

Update web.config file in asp.net

I am working on a web application which sits on a server and connects to various client machines based on the IPAddress.I have to change the IPAddress every time in the web.config file in order to connect to a particular client machine.

I want to put a text box where i can enter the ipaddress and it updates web.config file based on the button click which should eventually connect to the respective client machine.

Is it possible to do this way or i am thinking the wrong way ?

Can any one guide me in the right path ?

It sounds to me like your thinking is backwards.

If the application is dependent on you inputting an IP address every time, why store it in the web.config? Why not just build that into the application as part of the process to connect to the machine?

Run application page, request IP input, utilize input to connect to targeted machine.

The config file is meant for rarely changing settings and other application configuration data. This is a value that is needed on a per use basis, so request it on a per use basis.

If you have a set list of IP Addresses that you're always connecting to, you can store a delimited list in the web.config and then parse it. Something like:

<add key="IPAddressList" value="192.168.1.2;192.168.10.1;192.168.15.16" />

Then, in your application, just split and loop through the list:

foreach(string ip in  ConfigurationManager.AppSettings["IPAddressList"].Split(';'))
   //connect to server (ip = the IP Address)

If you're dependent on input each time, then it might just be easiest to save a List of IP Addresses to the Application.Cache and update that via your page (does it need to persist?).

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