I want to be able to determine programmatically if the System.webServer/Security/requestFiltering section exists inside the the web.config file of my application. I am able to do it for other sections like system.web using the code below, but so far no luck wit开发者_开发知识库h system.WebServer.
var config = WebConfigurationManager.OpenWebConfiguration("~");
HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
Label1.Text = section.MaxRequestLength.ToString();
Why don't you read the web.config just like any XML file and find the nodes that way? You could do something like this:
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...
}
精彩评论