在添加动态web配置价值?如何+最好的方法 [英] Adding values in web config dynamically? How To + Best way
本文介绍了在添加动态web配置价值?如何+最好的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想出了阅读,写作和asp.net web.config文件中的动态添加值。心里有很多想法,但我只是瓦纳知道什么是动态web配置添加值的最佳方式。
i just came up with the reading, Writing and adding values dynamically in web.Config in asp.net. Have many ideas in mind, but i just wana know what is the best way of adding values in web config dynamically.
例如在我的情况下,我必须添加
for example in my case i have to add
<identity userName="someDomain\User" password="password" impersonate="true" />
在
in
从code后面的Web配置标签。
tag in web config from code behind.
等待良好的反应。
推荐答案
我把你和你想要的code是:
I got you and the code you want is :
public void saveIdentity(string username, string password, bool impersonate)
{
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
IdentitySection identitySection = (IdentitySection)objConfig.GetSection("system.web/identity");
if (identitySection != null)
{
identitySection.UserName = username;
identitySection.Password = password;
identitySection.Impersonate = impersonate;
}
objConfig.Save();
}
这篇关于在添加动态web配置价值?如何+最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文