我希望能够以编程方式确定我的应用程序的web.config文件中是否存在System.webServer/Security/requestFiltering节。我可以使用下面的代码对system.web等其他部分执行此操作,但到目前为止,使用system.WebServer还没有成功。
var config = WebConfigurationManager.OpenWebConfiguration("~");
HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
Label1.Text = section.MaxRequestLength.ToString();发布于 2011-02-10 22:36:04
为什么不像读取任何XML文件那样读取web.config并找到节点呢?你可以这样做:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("~/Web.config"));
XmlNode n = xmlDoc.SelectSingleNode("/configuration/System.webServer/Security/requestFiltering");
if (n != null)
{
// Do whatever you want...
}https://stackoverflow.com/questions/4937074
复制相似问题