如何操作web.config配置文件.
比如有一个配置文件:
<configuration>
<connectionStrings>
<add name= "server3 " connectionString= "xxxxxxxx " />
</connectionStrings>
</configuration>
如何获取或更改那些设置呢:
关键是获取一个Configuration 节点,可我怎么都获取不到本配置文件的节点:
比如一个配置文件web.config下面代码所在页的目录下:
Configuration config = WebConfigurationManager.OpenWebConfiguration( " ") as Configuration;
ConnectionStringsSection config_con = config.ConnectionStrings as ConnectionStringsSection;
ConnectionStringSettingsCollection config_con_ction = config_con.ConnectionStrings as ConnectionStringSettingsCollection;
Response.Write( "显示数字: "+config_con_ction[0]);
这里的话获取的节点不是web.config里面配置文件connectionStrings而是mach.config文件节点里面的,他郁闷了,OpenWebConfiguration不是获的本web.config配置文件中的Configuration 根节点吗?
到底因该怎么样才能获取到COnfiguration 跟节点,并显示出内容 XXXXXXX呢。
------解决方案--------------------Configuration config = WebConfigurationManager.OpenWebConfiguration( " ") as Configuration;
> > > > >
Configuration config = WebConfigurationManager.OpenWebConfiguration(null) as Configuration;
以空引用 null 表示当前应用程序根目录