我已经编写了自己的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,并通过上面的相同函数运行它。
但是,这样,我的sitemappath (绑定到站点地图)在每个页面上都不会返回任何内容。
发布于 2010-11-15 21:31:25
最后,这被证明是一个非常简单的修复方法。我所需要做的就是检查参数是否是url中的第一个参数。如果不是,我也需要去掉&符号-这样它就是startpos - 1
干杯
https://stackoverflow.com/questions/4183752
复制相似问题