private CookieConfigEntity GetDefaultCookieConfig(string nodeName) { CookieConfigEntity defaultConfig = new CookieConfigEntity(); defaultConfig.NodeName = "defaultConfig"; defaultConfig.PersistType = "Web"; defaultConfig.SecurityLevel = "Middle"; //节点名默认作为Cookie的存储名 defaultConfig.Properties["cookieName"] = nodeName; defaultConfig.Properties["hashkey"] = "baeaaea5-3d57-4b98-abde-47ac0aa15d54"; defaultConfig.Properties["rc4key"] = "5cb8b18c-7b5e-4f7b-a7c2-4603a250f39b"; defaultConfig.Properties["domain"] = ((_httpAccessor.HttpContext == null || _httpAccessor.HttpContext.Request == null) ? "localhost" : _httpAccessor.HttpContext.Request.Host.Host); defaultConfig.Properties["path"] = "/"; defaultConfig.Properties["expires"] = "0"; defaultConfig.Properties["securityExpires"] = "20"; return(defaultConfig); }
private Dictionary <string, CookieConfigEntity> GetAllCookieConfig() { string path = CookieConfigFilePath; if (string.IsNullOrWhiteSpace(path) || File.Exists(path) == false) { return(new Dictionary <string, CookieConfigEntity>(0)); } Dictionary <string, CookieConfigEntity> dic = new Dictionary <string, CookieConfigEntity>(); XmlDocument doc = new XmlDocument(); doc.Load(CookieConfigFilePath); XmlNodeList nodeList = doc.GetElementsByTagName("cookies"); if (nodeList != null && nodeList.Count > 0) { foreach (XmlNode xmlNode in nodeList) { if (xmlNode == null) { continue; } CookieConfigEntity entity = new CookieConfigEntity(); entity.NodeName = xmlNode.Attributes["nodeName"] != null ? xmlNode.Attributes["nodeName"].Value : null; entity.PersistType = xmlNode.Attributes["persistType"] != null ? xmlNode.Attributes["persistType"].Value : null; entity.SecurityLevel = xmlNode.Attributes["securityLevel"] != null ? xmlNode.Attributes["securityLevel"].Value : null; if (string.IsNullOrWhiteSpace(entity.NodeName)) { throw new ApplicationException("Not set node name for cookie config in file '" + path + "'"); } if (dic.ContainsKey(entity.NodeName)) { throw new ApplicationException("Duplicated cookie config of node '" + entity.NodeName + "' in file '" + path + "'"); } if (string.IsNullOrWhiteSpace(entity.PersistType)) { entity.PersistType = "Auto"; // 如果没有配置persistType,则默认为web } if (string.IsNullOrWhiteSpace(entity.SecurityLevel)) { entity.SecurityLevel = "Middle"; // 如果没有配置securityLevel,则默认为Middle } foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Element) { if (entity.Properties.ContainsKey(childNode.Name)) { entity.Properties[childNode.Name] = childNode.InnerText; } else { entity.Properties.Add(childNode.Name, childNode.InnerText); } } } dic.Add(entity.NodeName, entity); } } return(dic); }