Jack-Leung

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
实现功能:通过传入的标记(name)获取该Url(前台得到后台一个数组,该数组通过遍历web.config生成)
前台:
<script language="javascript" type="text/javascript">
function setUrl(name) {
            var UrlList = <%=UrlList%>;
            for (var i in UrlList ) {
                var p =UrlList[i];
                if(p.indexOf(name) >= 0)
                {
                   var url = p.substr(p.indexOf('|')+1,p.length);
                   parent.location.href=url;
                }
            }
        }
</script>

后台:
public void GetUrl()
{
try
{
string filename = Server.MapPath("web.config");
XmlDocument xmldoc
= new XmlDocument();
xmldoc.Load(filename);
string[] url;
//得到顶层节点列表
XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
foreach (var top in topM)
{
XmlElement element
= top as XmlElement;
if (element != null)
{
if (element.Name.ToLower() == "appsettings")
{
XmlNodeList nodelist
= element.ChildNodes;
int index = 0;
if (nodelist.Count > 0)
{
url
= new string[nodelist.Count];
foreach (var node in nodelist)//读元素值XmlElement
{
XmlElement el
= node as XmlElement;
if (el != null)
{
if (el.Attributes["key"].InnerXml.ToLower().Contains("url"))
{
url[index]
= el.Attributes["key"].InnerXml + "|" + el.Attributes[1].Value + "/Default.aspx?userid=" + useridEncode + "&pwd=" + pwdEncode + "";
index
++;
}
}
}
for (int i = 0; i < index; i++)
{
if (i == 0)
UrlList
= "['" + url[i] + "',";
else if (i == index - 1)
UrlList
+= "'" + url[i] + "']";
else
UrlList
+= "'" + url[i] + "',";
}
}
break;
}
}
}
}
catch (Exception)
{
UrlList
= "['Default.aspx']";
}
}

  

编辑器加载中...

posted on 2011-09-01 15:30  Jack.leung  阅读(2307)  评论(0编辑  收藏  举报