我已经编写了自己的 staticsitemapprovider 来构建动态站点地图。我遇到的问题是,有时页面会在查询字符串中包含我需要忽略的其他参数。
Public Overrides Function FindSiteMapNode(ByVal rawUrl As String) As SiteMapNode
Dim startpos As Integer = 0
Dim endpos As Integer = 0
If rawUrl.Contains("pagetype=") Then
startpos = rawUrl.IndexOf("pagetype=")
endpos = rawUrl.IndexOf("&", startpos) + 1
If endpos >= startpos Then
'not the last param
rawUrl = rawUrl.Remove(startpos, endpos - startpos)
Else
'must be the last param
rawUrl = rawUrl.Remove(startpos)
End If
End If
Return MyBase.FindSiteMapNode(rawUrl)
End Function
我还重写了接收 HttpContect 对象的 FindSiteMapNode 函数。有了这个,我可以简单地找到该请求的 URL 并通过上面的相同函数运行它。
然而,我的站点地图路径(绑定到站点地图)在每个页面上都没有返回任何内容。