编程方式更改的web.config用C#(.NET) [英] Change a web.config programmatically with C# (.NET)
本文介绍了编程方式更改的web.config用C#(.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何修改/操纵的web.config
编程用C#?我可以使用一个配置对象,而且,如果是的话,我怎么能加载的web.config
进入配置对象?我想有一个完整的示例更改连接字符串。修改的的web.config后
应写回硬盘。
How can I modify / manipulate the web.config
programmatically with C# ? Can I use a configuration object, and, if yes, how can I load the web.config
into a configuration object ? I would like to have a full example changing the connection string. After the modification the web.config
should be written back to the harddisk.
推荐答案
这是一些code:
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["MyConnectionString"].ConnectionString = "Data Source=...";
configuration.Save();
请参阅在这篇文章,你可能需要看一看来的impersonation 。
See more examples in this article, you may need to take a look to impersonation.
这篇关于编程方式更改的web.config用C#(.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文