标签:
1、
/// <summary>
/// 从本地加载xml配置数据
/// </summary>
/// <returns></returns>
private static Dictionary<string, int> LoadRole()
{
Dictionary<string, int> dict = new Dictionary<string, int>();//键,值
string fileName = "~/config/RoleList.xml";
XmlDocument doc = new XmlDocument();
doc.Load(HttpContext.Current.Server.MapPath(fileName));
XmlNode root = doc.DocumentElement;
foreach (XmlNode node in root.ChildNodes)
{
XmlElement element = (XmlElement)node;
dict.Add(element.GetAttribute("Name"),int.Parse(element.GetAttribute("Id")));
}
return dict;
}
2、
if (!int.TryParse(context.Request["Dep"], out depId) || depId <= 0)
{
return new ResultMessage(false, "无效的部门编号!");
}
int.TryParse(context.Request["Dep"], out depId) 是异常强转为int,为空则为0
标签:
原文地址:http://www.cnblogs.com/weijiafd/p/4511118.html