Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从c#代码中读取配置文件中的节_C# - Fatal编程技术网

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

如何从c#代码中读取配置文件中的节,c#,C#,在通过c#读取配置部分时,我在第1行中得到一个错误 此处不允许应用程序相对虚拟路径“~”。 System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); SystemWebSectionGroup grp = (SystemWebSectionGroup)config.GetSectionGroup("sys

在通过c#读取配置部分时,我在第1行中得到一个错误

此处不允许应用程序相对虚拟路径“~”。

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

我的猜测是,调用OpenWebConfiguration时不允许使用“~”的值,但这只是阅读错误消息时的猜测。OpenWebConfiguration()的文档中说,如果您想要根web.config,就要传递
null

您是否也可以显示配置文件中的部分