private const long CACHE_EXPIRED = 31104000; // tính theo giây

        public HandlerMapping()
        {
            if (null != HttpContext.Current.Cache[CACHE_NAME])
            {
                try
                {
                    this.Domains = (DomainCollection)HttpContext.Current.Cache[CACHE_NAME];
                    return;
                }
                catch
                {
                }
            }

            string configFilePath = System.Web.HttpContext.Current.Server.MapPath("/HandlerMapping/HandlerMapping.config");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(configFilePath);

            this.Domains = new DomainCollection();

            if (xmlDoc != null && xmlDoc.DocumentElement.ChildNodes.Count > 0)
            {
                XmlNodeList nodeDomains = xmlDoc.DocumentElement.SelectNodes("//AllowDomains/AllowDomain");

                for (int domainIndex = 0; domainIndex < nodeDomains.Count; domainIndex++)
                {
                    string domainName = nodeDomains[domainIndex].Attributes["domain"].Value;
                    //string idenity = nodeDomains[domainIndex].Attributes["idenity"].Value;
                    Domain newDomain = new Domain(domainName, "");

                    XmlNodeList nodeHandlers = nodeDomains[domainIndex].SelectNodes("handler");

                    for (int handlerIndex = 0; handlerIndex < nodeHandlers.Count; handlerIndex++)
                    {
                        string key = nodeHandlers[handlerIndex].Attributes["key"].Value;
                        string assembly = nodeHandlers[handlerIndex].Attributes["assembly"].Value;
                        string method = nodeHandlers[handlerIndex].Attributes["method"].Value;
                        string parameters = nodeHandlers[handlerIndex].Attributes["params"].Value;
                        int cacheExpiration = Lib.Object2Integer(nodeHandlers[handlerIndex].Attributes["cache"].Value);
                        string allowRequestKey = nodeHandlers[handlerIndex].Attributes["AllowRequestKey"].Value;
                        
                        JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
                        List<string> listOfParams = new List<string>();
                        if (parameters != "")
                        {
                            listOfParams = jsSerializer.Deserialize<List<string>>("[" + parameters + "]");
                        }

                        newDomain.Handlers.Add(new Handler(key, assembly, method, cacheExpiration, allowRequestKey, listOfParams.ToArray()));
                    }

                    this.Domains.Add(newDomain);
                }

                CacheDependency fileDependency = new CacheDependency(configFilePath);
                HttpContext.Current.Cache.Insert(CACHE_NAME, this.Domains, fileDependency, DateTime.Now.AddSeconds(CACHE_EXPIRED), TimeSpan.Zero, CacheItemPriority.Normal, null);

            }
        }
 public void Add(Domain item)
 {
     this.List.Add(item);
 }