动态传递给查询字符串站点地图 [英] Dynamically pass querystring to sitemap
问题描述
您好我在母版每个Sitemap。我需要动态的查询字符串传递给我的地图。没有人得到这方面的经验。
这里是我的code
的web.sitemap
<?XML版本=1.0编码=UTF-8&GT?;
<站点地图的xmlns =http://schemas.microsoft.com/AspNet/SiteMap-File-1.0>
<的SiteMapNode URL =标题=员工福利描述=> <的SiteMapNode URL =〜/模块/ EB /公司/ CompanyList.aspx称号=公司列表描述=公司名单>
<的SiteMapNode URL =〜/模块/ EB /公司/ CompanyDetail.aspx称号=公司详细信息描述=公司详细信息>
<的SiteMapNode URL =〜/模块/ EB /员工/ EmployeeDetail.aspx称号=员工详细描述=员工详细信息/>
< /&的SiteMapNode GT;
< /&的SiteMapNode GT;
< /&的SiteMapNode GT;
< /网站地图>
Master.aspx
< ASP:的SiteMapPath ID =SiteMapPath1=服务器FONT-名称=微软新傣文
FONT-SIZE =0.9emPathSeparator =:SkipLinkText =字体粗体=FALSE
风格=FONT-FAMILY:'宋体',时代,衬线;字体大小:小
可见=真>
< CurrentNodeStyle前景色=#333333/>
< NodeStyle字体粗体=真前景色=#284E98/>
< PathSeparatorStyle字体粗体=真前景色=#507CD1/>
< RootNodeStyle字体粗体=真前景色=#507CD1/>
< / ASP:&的SiteMapPath GT;
顺便说一句。我的网站地图可能有多个分的SiteMapNode。例如:
companylist - > companydetail - > EmployeeDetail-> .....
我怎样才能查询字符串传递到其他子sitemapNope?
companylist - > companydetail的subID = 1 - &GT?; ?EmployeeDetail的subID = 2 - > ....
codeBehind:
保护串CustomersURL
{
得到
{
System.Text.StringBuilder URL =新System.Text.StringBuilder(〜/模块/ EB /公司/ CompanyList.aspx);
如果(条件)
{
(?参数1 = {0}@,someparameter)url.AppendFormat;
}
返回url.ToString();
}
}
.ASPX:
<的SiteMapNode URL ='<%#CustomersURL%GT;标题=公司列表描述=公司名单>
编辑:
检查从MSDN下面的解释,它exatly铲球您的问题:
http://msdn.microsoft。 COM / EN-US /库/ ms178425%28V = VS.100%29.aspx
私人无效的Page_Load(对象发件人,EventArgs的发送)
{
//该ExpandForumPaths方法被调用来处理
//将SITEMA preSOLVE事件。
SiteMap.SiteMa preSOLVE + =
新SITEMA presolveEventHandler(this.ExpandForumPaths);
}私人的SiteMapNode ExpandForumPaths(对象发件人,SITEMA presolveEventArgs E)
{
//当前节点重新$ P $在布告栏论坛psents一个帖子页面。
//克隆当前节点及其所有相关的家长。这个
//返回一个站点地图结点,开发者可以再
//散步,修改依次在每个node.Url财产。
//由于克隆节点是从底层分开
//网站导航结构,所做出的调整信息不
//影响网站的整体导航结构。
的SiteMapNode currentNode = SiteMap.CurrentNode.Clone(真);
的SiteMapNode tempNode = currentNode; //获取最近的标识。
INT forumGroupID = GetMostRecentForumGroupID();
INT forumID = GetMostRecentForumID(forumGroupID);
INT =帖子ID GetMostRecentPostID(forumID); //当前节点,并且它的父母,可修改成包括
相关的当前动态//查询字符串信息
//执行请求。
如果(0!=帖子ID)
{
tempNode.Url = tempNode.Url + postID.ToString()帖子ID =?;
} 如果((空=(tempNode = tempNode.ParentNode))及!&放大器;
(0!= forumID))
{
tempNode.Url = tempNode.Url + forumID.ToString()ForumID =?;
} 如果((空=(tempNode = tempNode.ParentNode))及!&放大器;
(0!= forumGroupID))
{
tempNode.Url = tempNode.Url + forumGroupID.ToString()ForumGroupID =?;
} 返回currentNode;
}
...
//这些方法都只是为示例的占位符。
//一种选择是使用的HttpContext或e.Context对象
//获取ID。
私人诠释GetMostRecentForumGroupID()
{
返回24;
}私人诠释GetMostRecentForumID(INT forumGroupId)
{
返回128;
}私人诠释GetMostRecentPostID(INT forumId)
{
返回317424;
}
您只需要勾对母版页的codebehind(在Page_Load事件)的SITEMA presolveEventHandler,并提供返回您的自定义的SiteMapNode功能 - 比如本例中的ExpandForumPaths - 和然后把它作为一个代表到SITEMA presolveEventHandler。
Hi I has one sitemap in masterpage. I need to dynamic pass querystring to my sitemap. Did anyone get experience with this. Here is my code
web.sitemap
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="Employee Benefit" description="">
<siteMapNode url="~/Module/EB/Company/CompanyList.aspx" title="Company list" description="Company List" >
<siteMapNode url="~/Module/EB/Company/CompanyDetail.aspx" title="Company Detail" description="Company Detail" >
<siteMapNode url="~/Module/EB/Employee/EmployeeDetail.aspx" title="Employee Detail" description="Employee Detail" />
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>
Master.aspx
<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Microsoft New Tai Lue"
Font-Size="0.9em" PathSeparator=" : " SkipLinkText="" Font-Bold="False"
style="font-family: 'Times New Roman', Times, serif; font-size: small"
Visible="True" >
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#284E98" />
<PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />
<RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />
</asp:SiteMapPath>
By the way. my sitemap may have multiple sub siteMapNode. For example
companylist -> companydetail -> EmployeeDetail->.....
How can I pass querystring to other sub sitemapNope ?
companylist -> companydetail?subID=1 -> EmployeeDetail?subID=2 ->....
CodeBehind :
protected string CustomersURL
{
get
{
System.Text.StringBuilder url = new System.Text.StringBuilder("~/Module/EB/Company/CompanyList.aspx");
if (condition)
{
url.AppendFormat(@"?param1={0}", someparameter);
}
return url.ToString();
}
}
.ASPX :
<siteMapNode url='<%# CustomersURL %> title="Company list" description="Company List" >
EDIT :
Check the following explanation from MSDN, it tackles your problem exatly :
http://msdn.microsoft.com/en-us/library/ms178425%28v=vs.100%29.aspx
private void Page_Load(object sender, EventArgs e)
{
// The ExpandForumPaths method is called to handle
// the SiteMapResolve event.
SiteMap.SiteMapResolve +=
new SiteMapResolveEventHandler(this.ExpandForumPaths);
}
private SiteMapNode ExpandForumPaths(Object sender, SiteMapResolveEventArgs e)
{
// The current node represents a Post page in a bulletin board forum.
// Clone the current node and all of its relevant parents. This
// returns a site map node that a developer can then
// walk, modifying each node.Url property in turn.
// Since the cloned nodes are separate from the underlying
// site navigation structure, the fixups that are made do not
// effect the overall site navigation structure.
SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
SiteMapNode tempNode = currentNode;
// Obtain the recent IDs.
int forumGroupID = GetMostRecentForumGroupID();
int forumID = GetMostRecentForumID(forumGroupID);
int postID = GetMostRecentPostID(forumID);
// The current node, and its parents, can be modified to include
// dynamic querystring information relevant to the currently
// executing request.
if (0 != postID)
{
tempNode.Url = tempNode.Url + "?PostID=" + postID.ToString();
}
if ((null != (tempNode = tempNode.ParentNode)) &&
(0 != forumID))
{
tempNode.Url = tempNode.Url + "?ForumID=" + forumID.ToString();
}
if ((null != (tempNode = tempNode.ParentNode)) &&
(0 != forumGroupID))
{
tempNode.Url = tempNode.Url + "?ForumGroupID=" + forumGroupID.ToString();
}
return currentNode;
}
...
// These methods are just placeholders for the example.
// One option is to use the HttpContext or e.Context object
// to obtain the ID.
private int GetMostRecentForumGroupID()
{
return 24;
}
private int GetMostRecentForumID(int forumGroupId)
{
return 128;
}
private int GetMostRecentPostID(int forumId)
{
return 317424;
}
You just need to hook to the SiteMapResolveEventHandler on the codebehind of the master page (on the Page_Load event) and provide a function that returns your custom SiteMapNode - such as the ExpandForumPaths in the example - and then pass it as a delegate to the SiteMapResolveEventHandler.
这篇关于动态传递给查询字符串站点地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!