简体   繁体   English

更新asp.net中的web.config文件

[英]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. 我正在一个Web应用程序上工作,该Web应用程序位于服务器上并基于IPAddress连接到各种客户端计算机。我每次必须在web.config文件中更改IPAddress才能连接到特定的客户端计算机。

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. 我想在文本框中输入ipaddress,然后根据按钮单击更新web.config文件,该按钮最终应连接到相应的客户端计算机。

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? 如果应用程序每次都依赖于您输入IP地址,为什么将其存储在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. 运行应用程序页面,请求IP输入,利用输入连接到目标机器。

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. 如果您有一个始终连接的IP地址的固定列表,则可以将定界列表存储在web.config中,然后对其进行解析。 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?). 如果您每次都依赖输入,那么将IP地址列表保存到Application.Cache并通过您的页面进行更新可能最简单(是否需要保留?)。

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

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