首页 > 技术文章 > 解析ASP,NET MVC 中 web.config XML文件 取出数据库类型

zemax 2016-07-13 17:25 原文

         /// <summary>
        /// 解析web.config   查询dbType类型
       /// </summary>
 
        private static void SetDBType()
        {
            #region 解析web.config   查询dbType类型
            string strPath = HttpContext.Current.Server.MapPath("/") + "Web.config";
            XmlDocument doc = new XmlDocument();
            doc.Load(strPath);
            string dbType = "";
            XmlNodeList nodeList = doc.SelectNodes(@"configuration/appSettings/add");
            foreach (XmlNode nodeitem in nodeList)
            {
                if (nodeitem.Attributes["key"] != null && nodeitem.Attributes["value"] != null)
                {

                    if (nodeitem.Attributes["key"].Value.ToString() == "DBType")
                    {
                        dbType = nodeitem.Attributes["value"].Value;
                    }
                }
            }

           
            #endregion
        }

  

推荐阅读