如何从c#代码中读取配置文件中的Section



在通过c#读取配置部分时,Am在第1行中遇到错误。

The application relative virtual path '~' is not allowed here.

System.Configuration.Configuration config =
    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");  
SystemWebSectionGroup grp = (SystemWebSectionGroup)config.GetSectionGroup("system.web");

我的猜测是,在调用OpenWebConfiguration时不允许使用"~"的值,但这只是读取错误消息的猜测。OpenWebConfiguration的文档(http://msdn.microsoft.com/en-us/library/ms151456(v=vs.110).aspx)表示,如果您想要根web.config,则传递null

最新更新