Web.config的读取问题
<UserConfig>
<Users>
<User>
<Name> 111 </Name>
<PassWord> 222 </PassWord>
</User>
<User>
<Name> 222 </Name>
<PassWord> 222 </PassWord>
</User>
</Users>
</UserConfig>
这样的一个配置节要如何读取啊?读取后如何转换为一个对象放到数组中?
我在Web.config文件中配置了这样的节点,然后想在用户登录时到里边读取所有的用户名与密码,然后进行对比,如果有这个用户并且密码也正确,就登录成功。
我现在就是不知道要怎么读取,并且转换。希望能有高手给指点指点!
------解决方案--------------------//已设用户名和密码
string logingadmin = ConfigurationSettings.AppSettings[ "loginadmin "].ToString().ToLower();
string pwdadmin = ConfigurationSettings.AppSettings[ "pwdadmin "].ToString().ToLower();
string loginother = ConfigurationSettings.AppSettings[ "loginother "].ToString().ToLower();
string pwdother = ConfigurationSettings.AppSettings[ "pwdother "].ToString().ToLower();
------解决方案--------------------把这些信息单独放到一个配置文件保存吧,类似这样读
static public void Load()
{
XmlReaderSettings settins = new XmlReaderSettings();
settins.IgnoreComments = true;
settins.IgnoreWhitespace = true;
codesXmlCache.Clear();
using (XmlReader reader = XmlReader.Create(Fw.Utility.AppConfigs.CodeXMLFile))
{
XmlDocument document = new XmlDocument();
document.Load(reader);
XmlNodeList list = document.SelectNodes( "codes " + "/ " + "code ");
foreach (XmlNode node in list)
{
Fw.Interface.Codes.ICode code = new Codes.GenericCode();
XmlNodeList items = node.SelectNodes( "item ");
foreach (XmlNode item in items)
{
Codes.GenericCodeItem codeItem = new GenericCodeItem();
codeItem.Name = item.Attributes[ "displayname "].Value;
codeItem.ItemName = item.Attributes[ "itemname "].Value;
codeItem.Value = item.Attributes[ "value "].Value;
code.Add(codeItem);
}
string codeName = node.Attributes[ "name "].Value;
codesXmlCache.Add(codeName, code);
}
}
System.Web.HttpApplicationState application = System.Web.HttpContext.Current.Application;
application.Lock();
application[ "CodesSetting "] = codesXmlCache;
application.UnLock();
}
------解决方案--------------------那就存cache里,一个用户名,正好配一个密码 cache.insert(key,pwd,...,...,..,..)