/// <summary>
        /// Removes the rule.
        /// </summary>
        /// <param name="id">The id of the rule to remove</param>
        public static void RemoveRule(Guid id)
        {
            WebSiteControllerConfig rules = GetFromConfigDB();

            rules.rules.Remove(id);
            rules.Update();
        }
        /// <summary>
        /// Removes the rule.
        /// </summary>
        /// <param name="id">The id of the rule to remove</param>
        public static void RemoveRule(string id)
        {
            WebSiteControllerConfig rules = GetFromConfigDB();

            rules.rules.Remove(new Guid(id));
            rules.Update();
        }
        /// <summary>
        /// Adds a new WebSiteControllerRule.
        /// </summary>
        /// <param name="siteCollection">The site collection.</param>
        /// <param name="page">The page to which the rule applied</param>
        /// <param name="ruleType">Type of the rule.</param>
        /// <param name="principal">The principal.</param>
        /// <param name="principalType">Type of the principal.</param>
        /// <param name="disabled">if set to <c>true</c> the rule is disabled.</param>
        /// <param name="appliesToSsl">if set to <c>true</c> the rule applies to SSL.</param>
        /// <param name="sequence">The sequence of the rule compared to other rules.</param>
        /// <param name="properties">The properties.</param>
        /// <returns>The resulting WebSiteControllerRule</returns>
        public static WebSiteControllerRule AddRule(
            SPWebApplication Webapp,
            string siteCollection,
            string page,
            string ruleType,
            string principal,
            WebSiteControllerPrincipalType principalType,
            bool disabled,
            bool appliesToSsl,
            int sequence,
            Hashtable properties)
        {
            WebApp = Webapp;
            WebSiteControllerConfig config = GetFromConfigDB();
            WebSiteControllerRule   rule   = new WebSiteControllerRule(
                siteCollection,
                page,
                ruleType,
                principal,
                principalType,
                disabled,
                appliesToSsl,
                sequence,
                config);

            rule.Name = rule.Id.ToString();

            if (properties != null)
            {
                foreach (DictionaryEntry property in properties)
                {
                    rule.Properties.Add(property.Key, property.Value);
                }
            }

            if (!IsDuplicateRule(rule))
            {
                config.rules.Add(rule);
                config.Update();
            }
            else
            {
                throw new SPDuplicateObjectException(rule + " is the same as another rule in the WebSiteControllerRules collection");
            }

            return(rule);
        }
        //private SPWebApplication WebApp;
        //private Guid guid;

        /// <summary>
        /// Creates the WebSiteControllerRules in config DB.
        /// </summary>
        public static void CreateInConfigDB()
        {
            if (!Exists())
            {
                if (HttpContext.Current != null)
                {
                    try
                    {
                        SPSite site = new SPSite(HttpContext.Current.Request.Url.OriginalString);
                        WebApp = site.WebApplication;
                    }
                    catch { };
                }

                if (WebApp != null && WebApp != SPAdministrationWebApplication.Local)
                {
                    lock (createlock)
                    {
                        WebSiteControllerConfig settings = new WebSiteControllerConfig(WebApp, Guid.NewGuid());
                        settings.Update();
                    }
                }

                /*
                 * else
                 * {
                 *  lock (createlock)
                 *  {
                 *
                 *      WebSiteControllerConfig settings = new WebSiteControllerConfig();
                 *      settings.Update();
                 *  }
                 * }
                 */
            }
        }