Hi sir,
i am using sitemappath for my website. i give a urls in web.sitemap page. my website urls contain 5 querystrings. how can we give a querystring values for all urls in codebehind. please help me
Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Praneeth KumarPosted Jun 9, 2011, 1:14 PM
This is the exact scenario for why the sitemapresolve eventhandler is created the . You can find this example in global.asax of the Personal WebSite Starter Kit. You'll want to make a few changes I suspect but this should be a good starting point.
Sub Application_Start(ByVal sender As [Object], ByVal e As EventArgs)
AddHandler SiteMap.SiteMapResolve, AddressOf Me.AppendQueryString
End Sub Function AppendQueryString(ByVal o As [Object], ByVal e As SiteMapResolveEventArgs) As SiteMapNode
If (Not (SiteMap.CurrentNode) Is Nothing) Then
Dim temp As SiteMapNode
temp = SiteMap.CurrentNode.Clone(True)
Dim u As Uri = New Uri(e.Context.Request.Url.ToString)
temp.Url = (temp.Url + u.Query)
If (Not (temp.ParentNode) Is Nothing) Then
temp.ParentNode.Url = (temp.ParentNode.Url + u.Query)
End If
Return temp
Else
Return Nothing
End If
End Function
Some improvements over the sample I suggest:
1) Don't run the query string appending on every request but only if SiteMap.CurrentNode is your "edit information" node.
2) Only add the query string to the parent node and not the entire parent hierarchy.