zhuguifei
2026-03-10 2c1fd10c6fbabb8e9f0e9f07fe66fb36c008e883
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Web;
 
namespace UEv143
{
    /// <summary>
    /// Config 的摘要说明
    /// </summary>
    public static class Config
    {
        private static bool noCache = true;
        private static JObject BuildItems()
        {
            //var json = File.ReadAllText(HttpContext.Current.Server.MapPath("config.json"));
            //return JObject.Parse(json);
 
            /*
                 * 2014-06-04,陈建伟
                 * 注释掉上面两行代码,并添加下段代码,使得 config.json 文件的 UrlPrefix 相关参数(共 8 个)返回的目录路径都是 controller.ashx 文件所在目录
                 * 通过这种方式,避免了每次调整 ueditor 安装目录后都需要需改 config.json 文件中关于 UrlPrefix 相关配置项的问题。
                 */
            var json = File.ReadAllText(HttpContext.Current.Server.MapPath("config.json"));
            var path = VirtualPathUtility.GetDirectory(HttpContext.Current.Request.Path);
            var ret = JObject.Parse(json);
            var urlPrefixList = ret["urlPrefixList"];
            var names = urlPrefixList != null ? urlPrefixList.Values<string>() : null;
            if (names == null || names.Count() == 0)
            {
                var list = new List<string>();
                var tmp = ret.ToList<KeyValuePair<string, JToken>>().Where(p => p.Key.EndsWith("urlprefix", StringComparison.CurrentCultureIgnoreCase));
                foreach (var item in tmp)
                {
                    list.Add(item.Key);
                }
            }
            foreach (var name in names)
            {
                ret.Remove(name);
                ret.Add(name, path);
            }
            return ret;
        }
 
        public static JObject Items
        {
            get
            {
                if (noCache || _Items == null)
                {
                    _Items = BuildItems();
                }
                return _Items;
            }
        }
        private static JObject _Items;
 
 
        public static T GetValue<T>(string key)
        {
            return Items[key].Value<T>();
        }
 
        public static String[] GetStringList(string key)
        {
            return Items[key].Select(x => x.Value<String>()).ToArray();
        }
 
        public static String GetString(string key)
        {
            return GetValue<String>(key);
        }
 
        public static int GetInt(string key)
        {
            return GetValue<int>(key);
        }
    }
}