2011-02-08 5 views
2

System.webServer/Security/requestFilteringセクションがアプリケーションのweb.configファイル内に存在するかどうかをプログラムで判断できます。 私はsystem.webのような他のセクションでは以下のコードを使用して実行できますが、これまでsystem.WebServerでは不運でした。System.webServer/Security/requestFilteringセクションがプログラムによって存在するかどうかを確認する方法?

var config = WebConfigurationManager.OpenWebConfiguration("~"); 

    HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection; 

Label1.Text = section.MaxRequestLength.ToString(); 

答えて

2

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... 
} 
関連する問題