Esempio n. 1
0
        private static CookieConfigEntity GetDefaultCookieConfig(string nodeName)
        {
            CookieConfigEntity defaultConfig = new CookieConfigEntity();

            defaultConfig.NodeName                      = "defaultConfig";
            defaultConfig.PersistType                   = "Auto";
            defaultConfig.SecurityLevel                 = "Low";
            defaultConfig.Properties["cookieName"]      = nodeName;
            defaultConfig.Properties["hashkey"]         = "di234fdgb-d3234kx-s534345-dfle-sdfiksdf";
            defaultConfig.Properties["rc4key"]          = "sdddf-09xk-dsddd-sssdf9sdf2d-09dsfks";
            defaultConfig.Properties["domain"]          = ((HttpContext.Current == null || HttpContext.Current.Request == null) ? "localhost" : HttpContext.Current.Request.Url.Host);
            defaultConfig.Properties["path"]            = "/";
            defaultConfig.Properties["expires"]         = "0";
            defaultConfig.Properties["securityExpires"] = "20";
            return(defaultConfig);
        }
Esempio n. 2
0
        private static Dictionary <string, CookieConfigEntity> GetAllCookieConfig()
        {
            string path = CookieConfigFilePath;

            if (string.IsNullOrWhiteSpace(path) || File.Exists(path) == false)
            {
                return(new Dictionary <string, CookieConfigEntity>(0));
            }
            return(GetWithLocalCache <Dictionary <string, CookieConfigEntity> >("WEB_CookieConfig_GetCookieConfig", () =>
            {
                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";
                        }
                        if (string.IsNullOrWhiteSpace(entity.SecurityLevel))
                        {
                            entity.SecurityLevel = "Low";
                        }
                        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;
            }, path));
        }