惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - 梅子黄时雨

离职反思 人际交往能力:远比你想象的重要 关于晋升 生产力提升计划 向企业一样的思考 在CentOS上搭建WordPress的博客系统 Some Useful LINQ Extension Methods MVC模式 IIS7.5配置 An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode. C# 整数和byte数组互换 显式接口成员实现 C#实现的堆栈 ASP.NET 验证控件 Gridview中合并单元格,某字段的内容相同时如何只显示一个,屏蔽相同列或行的内容(转) 动态SQL EXEC DELL 1520 笔记本拆机 关于表变量 华为致新员工书
C#winform 配置webconfig
梅子黄时雨 · 2011-09-02 · via 博客园 - 梅子黄时雨

今天公司老大让做一个web.config的配置工具,虽然好久没写winform的程序了,不过想想无非也就是操作XML文件嘛,信誓旦旦的说两个小时就可以了。结果时间操作才发现不对劲,读取普通的XML文件没问题,操作web.config就不行,总是找不到节点。悲剧啊,折腾了一上午。

偶然发现web.config最开始比普通xml文件多了一行 xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0",心里一动,把这一行删掉,这下可以了,看来问题就出在这个身上啊。百度了一下,发现这个东东原来是xml的命名空间(汗,头一次知道这个东东),找到问题就好办了:

        /// <summary>
        /// 获取连接字符串信息
        /// </summary>
        public string GetConnectionString()
        {
            return QueryNode("/configuration/connectionStrings", "name", "ConnectionString", "connectionString");
        }


        private string QueryNode(string xpath, string nameField, string nameValue, string valueField)
        {

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            xpath = xpath.Replace("/", "//ww:");
            XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);
            ns.AddNamespace("ww", doc.DocumentElement.NamespaceURI);
            XmlNode pareNode = doc.SelectSingleNode(xpath, ns);
        }