从config中的特定位置路径获取maxRequestLength值

时间:2015-12-04 17:21:51

标签: config maxrequestlength

我为不同的位置路径设置了几个不同的maxRequestLengths。如何获取我要查找的特定位置路径的值?

以下是配置中的内容: enter image description here

1 个答案:

答案 0 :(得分:1)

检查出来

using System;
using System.Collections;
using System.Configuration;

class DisplayLocationInfo
{
    static void Main(string[] args)
    {
        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConfigurationLocationCollection myLocationCollection = config.Locations;
        foreach (ConfigurationLocation myLocation in myLocationCollection)
        {
            Console.WriteLine("Location Path: {0}", myLocation.Path);
            Configuration myLocationConfiguration = myLocation.OpenConfiguration();
            Console.WriteLine("Location Configuration File Path: {0}", myLocationConfiguration.FilePath);
        }
        Console.WriteLine("Done...");
        Console.ReadLine();
    }
}

https://msdn.microsoft.com/en-us/library/system.configuration.configurationlocation(v=vs.100).aspx