读取asp.net中的自定义配置文件 [英] read custom config file in asp.net
本文介绍了读取asp.net中的自定义配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从asp.net的C#代码中使用WebConfigurationManager从自定义配置文件(例如abc.config)中读取连接字符串?
How do I read connection strings from custom config file (say abc.config) using WebConfigurationManager from asp.net's C# code?
Configuration conf = WebConfigurationManager.OpenWebConfiguration("~/abc.config");
这似乎不起作用。
推荐答案
我认为您无法使用webconfigurationmanager来阅读它。您将像读取任何xml文件一样阅读该文件,因为它是xml文件
I dont think you can read it with webconfigurationmanager. you will have read like any xml file as it is an xml file
public static string GetSingleValue(string strXPathExpression, string strAttributeName)
{
XmlNode node = GetNode(strXPathExpression);
if (node != null)
{
XmlAttribute attribute = node.Attributes[strAttributeName];
if (attribute != null)
return attribute.Value;
}
return string.Empty;
}
这篇关于读取asp.net中的自定义配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文