예제 #1
0
 /// <summary>
 /// Gets text value from the given XmlElement for node specified by the given XPath expression
 /// </summary>
 /// <param name="element">XML element to look into</param>
 /// <param name="xPath">XPath expression identifying the node to get value for</param>
 /// <param name="nsmgr">XML namespace to use</param>
 /// <returns>Text value for the required node</returns>
 static public string GetElementValue(XmlElement element, string xPath, XmlNamespaceManager nsmgr)
 {
     return(XmlUtility.GetElementValue(element, xPath, nsmgr, string.Empty));
 }
예제 #2
0
 /// <summary>
 /// Gets text value from the given XmlElement for node specified by the given XPath expression
 /// </summary>
 /// <param name="element">XML element to look into</param>
 /// <param name="xPath">XPath expression identifying the node to get value for</param>
 /// <returns>Text value for the required node</returns>
 static public string GetElementValue(XmlElement element, string xPath)
 {
     return(XmlUtility.GetElementValue(element, xPath, null, string.Empty));
 }
예제 #3
0
 /// <summary>
 /// Gets text value from the given XmlElement for node specified by the given XPath expression
 /// </summary>
 /// <param name="element">XML element to look into</param>
 /// <param name="xPath">XPath expression identifying the node to get value for</param>
 /// <param name="defaultValue">The default value to return if the specified node could not be found</param>
 /// <returns>Text value for the required node</returns>
 static public string GetElementValue(XmlElement element, string xPath, string defaultValue)
 {
     return(XmlUtility.GetElementValue(element, xPath, null, defaultValue));
 }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="webConfigContent"></param>
        /// <param name="cookieDomain"></param>
        /// <returns></returns>
        public static void UpdateWebConfigCookieDomain(string cookieDomain)
        {
            // LOCATE WEB CONFIG
            string webConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "web.config");

            if (File.Exists(webConfigPath))
            {
                // TRACK REPLACEMENTS
                Dictionary <string, string> configReplacements = new Dictionary <string, string>();

                // READ CONTENT
                XmlDocument webConfigXmlDocument = new XmlDocument();
                webConfigXmlDocument.Load(webConfigPath);

                // LOOP NODES LOOKING FOR DOMAINS
                string[] xPathNodes = new string[] { "system.web/authentication/forms", "system.web/anonymousIdentification" };
                foreach (string xPath in xPathNodes)
                {
                    // LOCATE THIS ELEMENT
                    XmlElement element = XmlUtility.GetElement(webConfigXmlDocument.DocumentElement, xPath, false);
                    if (element != null)
                    {
                        // CHECK THE CURRENT COOKIE DOMAIN
                        string currentDomain = XmlUtility.GetAttributeValue(element, "domain", string.Empty);
                        if (currentDomain != cookieDomain)
                        {
                            // DOMAIN MISMATCH, WE MUST UPDATE THIS NODE
                            string xmlBefore = element.OuterXml;
                            if (string.IsNullOrEmpty(cookieDomain))
                            {
                                // WE MUST REMOVE THE DOMAIN
                                element.RemoveAttribute("domain");
                            }
                            else
                            {
                                // WE MUST UPDATE THE NODE
                                element.SetAttribute("domain", cookieDomain);
                            }
                            string xmlAfter = element.OuterXml;
                            if (xmlBefore != xmlAfter)
                            {
                                configReplacements[xmlBefore] = xmlAfter;
                            }
                        }
                    }
                }

                // ONLY SAVE CHANGES IF WE FOUND SOMETHING TO FIX
                if (configReplacements.Count > 0)
                {
                    // GET RAW WEB.CONFIG CONTENT
                    string webConfigContent = File.ReadAllText(webConfigPath);
                    foreach (string findValue in configReplacements.Keys)
                    {
                        // MAKE REPLACEMENTS, MINIFYING ANY CHANGES TO WHITESPACE ETC.
                        webConfigContent = webConfigContent.Replace(findValue, configReplacements[findValue]);
                    }

                    // SAVE THE WEB.CONFIG
                    File.WriteAllText(webConfigPath, webConfigContent);
                }
            }
        }