开发者

How to check if the System.webServer/Security/requestFiltering section exists programmatically?

开发者 https://www.devze.com 2023-02-09 13:44 出处:网络
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 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...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消