Welcome to MSDN Blogs Sign in | Join | Help

SiteMapProvider and spaces in querystrings

A user found an interesting issue in the SiteMapProvider code.  It seems that if you have a node that has a url such as: "~/home.aspx?p=some text"  (notice the space in the query string) and you are actually navigated to that url, SiteMap.CurrentNode doesn't actually return the correct node.  The reason for this is that the url actually comes in as:  "/home.aspx?p=some%20text". 

Now, firstly, this is a bug, and it's been filed to be addressed in the future but what (if any) is the workaround?  This one is tricky because the issue is pretty deep.  You need a custom provider and the appropriate method overridden.  When the user raised the issue, I thought about it and decided I could come up with the solution in 5 minutes or let him struggle with it for an hour.  What do you think I did?

Here's the custom provider:

Public Class testProvider : Inherits XmlSiteMapProvider

    
Public Overrides Function FindSiteMapNode(ByVal context As System.Web.HttpContext) As System.Web.SiteMapNode
        
Dim node As SiteMapNode = MyBase.FindSiteMapNode(context)

        
If node Is Nothing Then
            If context Is Nothing Then
                Return Nothing
            End If

            Dim queryString As String = CType(context.CurrentHandler, Page).ClientQueryString

            
Dim pageUrl As String = HttpUtility.UrlDecode(context.Request.Path & "?" & queryString)
            node =
MyBase.FindSiteMapNode(pageUrl)
        
End If

        Return node
    
End Function

End
Class
Published Wednesday, March 08, 2006 12:23 AM by dannychen
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# What's wrong with ASP.NET provider model? - The XmlSiteMapProvider

Besides the problem with spaces in query strings (the same thing happens for the entire URL), you cannot

Saturday, April 07, 2007 5:43 PM by Paulo Morgado

# O que há de errado com o modelo de Providers do ASP.NET? - XmlSiteMapProvider

Além do problema com espaços em query strings (o mesmo acontece para todo o URL), não se pode derivar

Saturday, April 07, 2007 6:28 PM by Paulo Morgado

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker