开发者

Ignoring specific query string parameters in custom sitemapprovider

I’ve written my own staticsitemapprovider which builds a dynamic site map. The problem I have is tha开发者_Python百科t sometimes pages will have additional parameters in the query string which I need to ignore.

    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

I've also overridden the FindSiteMapNode function that takes in a HttpContect object. With this I simple find the URL of that request and run it though the same function above.

However with this my sitemappath (which is bound to the site map) returns nothing on every page.


In the end this turned out to be a very simple fix. All i needed to do was check to see if the the parameter was the first in the url. If it wasn't, I aslo needed to remove the ampersand - so it would be startpos - 1

Cheers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜