读取web.config中单个节点的方法 (读取xml文件的方法测试完毕,成功)
引用名称空间:
using System.Xml;
代码部分(以
maxRequestLength
节点为例进行说明):
XmlDocument doc=new XmlDocument();
//Request.PhysicalApplicationPath取得config文件路径
doc.Load(Path.Combine(Request.PhysicalApplicationPath,"web.config"));
XmlNode node=doc.SelectSingleNode(" configuration/system.web/httpRuntime/@maxRequestLength");
doc.Load(Path.Combine(Request.PhysicalApplicationPath,"web.config"));
XmlNode node=doc.SelectSingleNode(" configuration/system.web/httpRuntime/@maxRequestLength");
double length=Convert.ToDouble(node.Value);
web.config中的部分:
<httpRuntime maxRequestLength="102400" />