在.net2.0中新增类HttpRuntimeSection :
static public double getMaxlength()
static public double getMaxlength()
{
System.Web.Configuration.HttpRuntimeSection hrs = new System.Web.Configuration.HttpRuntimeSection();
//return hrs.MaxRequestLength * 1024;
return hrs.MaxRequestLength ;
}
System.Web.Configuration.HttpRuntimeSection hrs = new System.Web.Configuration.HttpRuntimeSection();
//return hrs.MaxRequestLength * 1024;
return hrs.MaxRequestLength ;
}
asp.net2.0中读取web.config数据库连接字符串2种方法
方法一:
string myConn = System.Configuration.ConfigurationManager.ConnectionStrings["sqlConnectionString"].ConnectionString;
方法二:
string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["sqlConnectionString"].ToString();
读取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" />
读取结果:
length = 102400(100M)