示例#1
0
文件: AppHelper.cs 项目: kangcy/myapi
        /// <summary>
        /// 敏感词
        /// </summary>
        public static List <string> GetDirtyWord()
        {
            try
            {
                List <string> list = redis.HashGetAllValues <string>("DirtyWord");
                if (list.Count == 0)
                {
                    string str      = string.Empty;
                    string filePath = System.Web.HttpContext.Current.Server.MapPath("~/Config/dirtyword.config");
                    if (System.IO.File.Exists(filePath))
                    {
                        StreamReader sr = new StreamReader(filePath, Encoding.Default);
                        str = sr.ReadToEnd();
                        sr.Close();
                    }
                    list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(str);

                    var index = 0;
                    list.ForEach(x =>
                    {
                        redis.HashSet <string>("DirtyWord", index++.ToString(), x);
                    });
                }
                return(list);
            }
            catch (Exception ex)
            {
                return(new List <string>());
            }
        }