在运行时在Web配置中添加数据 [英] Add data in web config at run time

查看:50
本文介绍了在运行时在Web配置中添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在asp dot net中添加数据或编辑web.config文件。

How we can add data or edit web.config file in asp dot net.

推荐答案

不知道你为什么要这样做。因为编辑web.config将回收AppPool并重新启动应用程序。



仍然,使用使用C#2.0编辑和加密Web.Config章节 [ ^ ]
No idea why you want this. Because editing the web.config will recycle the AppPool and application will be restarted.

Still , use Edit and Encrypt Web.Config Sections Using C# 2.0[^]


// You will have to load the config somehow. Either by the exe filename or the config filepath directly 
var cfg = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
var setting = new ConnectionStringSettings
                    {
                        ConnectionString = "hello=123",
                        Name = "123test"
                    }
cfg.ConnectionStrings.ConnectionStrings.Add(setting);
cfg.Save();





您可以使用WebConfigurationManager.OpenWebConfiguration Method [ ^ ]


这篇关于在运行时在Web配置中添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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