阅读和书面方式键在WebConfigEditor的AppSettings [英] Reading and Writting keys to appsettings in WebConfigEditor

查看:121
本文介绍了阅读和书面方式键在WebConfigEditor的AppSettings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目包含web.config文件和外部的appSettings文件。我想提出一个WebConfig编辑器有选择阅读的AppSettings从web.config中和外部appSetting文件来显示他们的网页键。
此外,我允许用户通过点击删除按钮来删除任意键。
此外,用户还可以通过点击更新button.Or更新任何键值
他还可以通过点击添加新键按钮插入新的密钥。

My project contains web.config file and an external appSettings file. I am making a WebConfig Editor that has options to Read AppSettings key from web.config and external appSetting file to display them on webPage. Also, I am allowing user to delete any key by clicking on Remove button. Moreover, user can also update any key's value by clicking on update button.Or he can also insert new key by clicking on Add New Key button.

我现在面临的关键问题是,whenfever我尝试添加一个新的密钥,它被插入到
web.config文件不如预期,但同时它增加了所有键present外部的appSettings文件到web.config文件(这是突然的行为)。

The key issue I am facing is that whenfever I try to add a new key , it gets inserted into web.config file as expected , but at the same time it adds all the keys present in external appSettings file into web.config ( which is abrupt behavior).

如何阻止外部的appSettings键,这种迁移文件到web.config文件上的任意键的更新/删除/添加功能?

How to stop this migration of keys from external appSettings file to web.config on any key's update / delete/ add function?

推荐答案

有关阅读,把外部文件中的配置文件夹下的根,然后用这个code根据从网络读取键名读取键/值。配置或外部文件。

For reading, put external file in Config folder under root and then use this code to read key/values based on key name it read from web.config or external file.

// get from web.config                                                                            
String myKey = ConfigurationManager.AppSettings.Get("Key1");
String str += "AppSetting value from web.config:" + myKey;
// get from external AppSetting file
myKey = ConfigurationManager.AppSettings.Get("Key2");
String str2 += "AppSetting value from external AppSetting file:" + myKey;                                                            

,其中键1是在外部配置文件web.config文件和密钥2

where Key1 is in web.config and Key2 in external config file

也结果
 找人键值使用的foreach 循环

foreach (string key in ConfigurationManager.AppSettings)
{ 
    string value = ConfigurationManager.AppSettings[key];
    Console.WriteLine("Key: {0}, Value: {1}", key, value);
}

这篇关于阅读和书面方式键在WebConfigEditor的AppSettings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆