/// <summary> /// Get the current settings from the xml config file. /// </summary> /// <returns></returns> public static RequestFilterSettings GetSettings() { var settings = (RequestFilterSettings)DataCache.GetCache(RequestFilterConfig); if (settings == null) { settings = new RequestFilterSettings(); string filePath = Common.Utilities.Config.GetPathToFile(Common.Utilities.Config.ConfigFileType.DotNetNuke); // Create a FileStream for the Config file using (var fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var doc = new XPathDocument(fileReader); XPathNodeIterator ruleList = doc.CreateNavigator().Select("/configuration/blockrequests/rule"); while (ruleList.MoveNext()) { try { string serverVar = ruleList.Current.GetAttribute("servervar", string.Empty); string values = ruleList.Current.GetAttribute("values", string.Empty); var ac = (RequestFilterRuleType)Enum.Parse(typeof(RequestFilterRuleType), ruleList.Current.GetAttribute("action", string.Empty)); var op = (RequestFilterOperatorType)Enum.Parse(typeof(RequestFilterOperatorType), ruleList.Current.GetAttribute("operator", string.Empty)); string location = ruleList.Current.GetAttribute("location", string.Empty); var rule = new RequestFilterRule(serverVar, values, op, ac, location); settings.Rules.Add(rule); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(new Exception(string.Format("Unable to read RequestFilter Rule: {0}:", ruleList.Current.OuterXml), ex)); } } } if (File.Exists(filePath)) { // Set back into Cache DataCache.SetCache(RequestFilterConfig, settings, new DNNCacheDependency(filePath)); } } return(settings); }
/// <summary> /// Get the current settings from the xml config file /// </summary> public static RequestFilterSettings GetSettings() { var settings = (RequestFilterSettings) DataCache.GetCache(RequestFilterConfig); if (settings == null) { settings = new RequestFilterSettings(); string filePath = Common.Utilities.Config.GetPathToFile(Common.Utilities.Config.ConfigFileType.DotNetNuke); //Create a FileStream for the Config file var fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var doc = new XPathDocument(fileReader); XPathNodeIterator ruleList = doc.CreateNavigator().Select("/configuration/blockrequests/rule"); while (ruleList.MoveNext()) { try { string serverVar = ruleList.Current.GetAttribute("servervar", string.Empty); string values = ruleList.Current.GetAttribute("values", string.Empty); var ac = (RequestFilterRuleType) Enum.Parse(typeof (RequestFilterRuleType), ruleList.Current.GetAttribute("action", string.Empty)); var op = (RequestFilterOperatorType) Enum.Parse(typeof (RequestFilterOperatorType), ruleList.Current.GetAttribute("operator", string.Empty)); string location = ruleList.Current.GetAttribute("location", string.Empty); var rule = new RequestFilterRule(serverVar, values, op, ac, location); settings.Rules.Add(rule); } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.LogException(new Exception(string.Format("Unable to read RequestFilter Rule: {0}:", ruleList.Current.OuterXml), ex)); } } if ((File.Exists(filePath))) { //Set back into Cache DataCache.SetCache(RequestFilterConfig, settings, new DNNCacheDependency(filePath)); } } return settings; }