在SiteMap中写入固定节点:
1 <?xml version="1.0" encoding="utf-8" ?>
2 <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
3 <siteMapNode url="Forum.aspx" title="FLT Forum" description="">
4 <siteMapNode url="Topic.aspx" title="帖子列表" description="" >
5 <siteMapNode url="Post.aspx" title="查看帖子" description="" />
6 </siteMapNode>
7 </siteMapNode>
8 </siteMap>
基本上这个只标识一下网站结构2 <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
3 <siteMapNode url="Forum.aspx" title="FLT Forum" description="">
4 <siteMapNode url="Topic.aspx" title="帖子列表" description="" >
5 <siteMapNode url="Post.aspx" title="查看帖子" description="" />
6 </siteMapNode>
7 </siteMapNode>
8 </siteMap>
在master页的page_load中注册事件:
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack)
4 {
5 SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ForumPath);
6 }
7 }
事件处理代码:2 {
3 if (!IsPostBack)
4 {
5 SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.ForumPath);
6 }
7 }








































下面是3个方法,返回ForumID,TopID,PostID3个参数
1 private string getForumID(out string strClassName)
2 {
3 string strForumID = "";
4 if (System.Web.HttpContext.Current.Request.QueryString["ForumID"] != null)//这里必须要写System.Web.HttpContext.Current.Request.QueryString,而不能直接写Request.QueryString,这个问题在csdn上很长时间没解决啊,后来在msdn上一位朋友指点.
5 {
6 strForumID=System.Web.HttpContext.Current.Request.QueryString["ForumID"].ToString();
7 strClassName = xxx;//通过数据库或者Dataset获取分类名
8 return strForumID;
9 }
10 else
11 {
12 strPartName = "";
13 return strForumID;
14 }
15
16 }
17
18 private string getTopID(out string strTopName)
19 {
20 string strTopID = "";
21
22 if (System.Web.HttpContext.Current.Request.QueryString["TopID"] != null)
23 {
24 strTopID = System.Web.HttpContext.Current.Request.QueryString["TopID"].ToString();
25 strTopName = xxx;//同上
26 return strTopID;
27 }
28 else
29 {
30 strTopName = "";
31 return strTopID;
32 }
33 }
34
35 private string getPostID(out string strPostTitle)
36 {
37 string strPostID = "";
38
39 if (System.Web.HttpContext.Current.Request.QueryString["PostID"] != null)
40 {
41 strPostID = System.Web.HttpContext.Current.Request.QueryString["PostID"].ToString();
42 strPostTitle = xxx;//同上
43 return strPostID;
44 }
45 else
46 {
47 strPostTitle = "";
48 return strPostID;
49 }
50 }
2 {
3 string strForumID = "";
4 if (System.Web.HttpContext.Current.Request.QueryString["ForumID"] != null)//这里必须要写System.Web.HttpContext.Current.Request.QueryString,而不能直接写Request.QueryString,这个问题在csdn上很长时间没解决啊,后来在msdn上一位朋友指点.
5 {
6 strForumID=System.Web.HttpContext.Current.Request.QueryString["ForumID"].ToString();
7 strClassName = xxx;//通过数据库或者Dataset获取分类名
8 return strForumID;
9 }
10 else
11 {
12 strPartName = "";
13 return strForumID;
14 }
15
16 }
17
18 private string getTopID(out string strTopName)
19 {
20 string strTopID = "";
21
22 if (System.Web.HttpContext.Current.Request.QueryString["TopID"] != null)
23 {
24 strTopID = System.Web.HttpContext.Current.Request.QueryString["TopID"].ToString();
25 strTopName = xxx;//同上
26 return strTopID;
27 }
28 else
29 {
30 strTopName = "";
31 return strTopID;
32 }
33 }
34
35 private string getPostID(out string strPostTitle)
36 {
37 string strPostID = "";
38
39 if (System.Web.HttpContext.Current.Request.QueryString["PostID"] != null)
40 {
41 strPostID = System.Web.HttpContext.Current.Request.QueryString["PostID"].ToString();
42 strPostTitle = xxx;//同上
43 return strPostID;
44 }
45 else
46 {
47 strPostTitle = "";
48 return strPostID;
49 }
50 }
总结一下,这个方法对于结构比较简单(主要是深度比较小的)的网站,个人感觉要比操作XML文件简单,直接写程序就可以实现动态修改了,但是对于结构比较复杂(深度比较大的)网站,还是写XML比较直接.