0

Hi all,

Wondering if anyone can help me with this issue. I am using a SqlSiteMapProvider (inherits from SiteMapProvider) to build a menu on my site from an Oracle DB. This menu is built according to the user type, ie, user type A's menu is different from user type B. However the problem that I am having is that if I log as type A, the menu loads as expected, however if I log straight in again as type B the site will still display type A's menu, and vice versa. Its seems to me that the menu is being loaded into memory somehow, and what I actually need it to do is reload the sitemap each time someone logs in. If I put debugs in the SqlSiteMapProvider class it only seems to fire the 'New' constructor during the first login and not each time thereafter (Unless I close down Visual Studio and start again).

Basically, what I think I need is to force the siteMapProvider to reload, but I am not sure how to do this!

As you can probably tell, I am new to using these navigation controls, so any help would be really appreciated. I am really banging my head against a brick wall over this one!

Regards,

David.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by mirib
0

ps, here is my code for the SqlSiteMapProvider. I don't understand why this class doesnt reload each time at run time. I would have thought that it was fired each time when the application was loaded.

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Configuration.Provider
Imports System.IO
Imports System.Security.Permissions
Imports System.Web
Imports CuOnline.DAL.DatabaseAccess
Imports CuOnline.BL.CUOfficeManager



Namespace CuWebSite.ApplicationMenu

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class SqlSiteMapProvider
        Inherits SiteMapProvider

        Private parentSiteMapProvider As SiteMapProvider = Nothing
        Private simpleTextProviderName As String = Nothing
        Private aRootNode As SiteMapNode = Nothing
        Private siteMapNodes As ArrayList = Nothing
        Private childParentRelationship As ArrayList = Nothing
        Private menuLists As StandardClasses.MenuCollection = Nothing
        Private menuEach As StandardClasses.menuClass = Nothing
        Private execUser As String = Nothing
        Private strSession As String = Nothing
        Private cCUID As String = Nothing
        Private userArray As ArrayList = Nothing

        ' A default constructor. The Name property is initialized in the
        ' Initialize method.
        Public Sub New()
        End Sub 'New

        'Refresh Menus
        Public Sub Refresh()

            aRootNode = Nothing
            menuEach = Nothing
            execUser = Nothing
            cCUID = Nothing
            strSession = Nothing

            childParentRelationship.Clear()
            siteMapNodes.Clear()
            menuLists.Clear()
            userArray.Clear()

            Dim cuoffice As CUOffice = System.Web.HttpContext.Current.Session("cuoffice")
            cCUID = cuoffice.cuid
            Dim member As Member = System.Web.HttpContext.Current.Session("member")
            execUser = member.memberType
            strSession = member.sessionNo

            siteMapNodes = New ArrayList()
            childParentRelationship = New ArrayList()
            userArray = New ArrayList()
            userArray.Add(ReturnDbParam("pc_cu_id", cCUID))
            userArray.Add(ReturnDbParam("pc_member_type", execUser))
            'userArray.Add(ReturnDbParam("pn_session_no", strSession))
            FillMenus(userArray, "pkdb_web_menus.f_get_main_menu", menuLists)
            ' Build the site map in memory.
            LoadSiteMapFromStore()

        End Sub

        ' Implement the CurrentNode property.
        Public Overrides ReadOnly Property CurrentNode() As SiteMapNode
            Get
                Dim currentUrl As String = FindCurrentUrl()
                ' Find the SiteMapNode that represents the current page.
                Dim aCurrentNode As SiteMapNode = FindSiteMapNode(currentUrl)
                Return aCurrentNode
            End Get
        End Property

        ' Implement the RootNode property.
        Public Overrides ReadOnly Property RootNode() As SiteMapNode
            Get
                Return aRootNode
            End Get
        End Property

        'Removes current Node
        Protected Overrides Sub RemoveNode(ByVal anode As SiteMapNode)
            Me.RemoveNode(anode)
        End Sub

        ' Implement the ParentProvider property.
        Public Overrides Property ParentProvider() As SiteMapProvider
            Get
                Return parentSiteMapProvider
            End Get
            Set(ByVal value As SiteMapProvider)
                parentSiteMapProvider = value
            End Set
        End Property

        ' Implement the RootProvider property.
        Public Overrides ReadOnly Property RootProvider() As SiteMapProvider
            Get
                ' If the current instance belongs to a provider hierarchy, it
                ' cannot be the RootProvider. Rely on the ParentProvider.
                If Not (Me.ParentProvider Is Nothing) Then
                    Return ParentProvider.RootProvider
                    ' If the current instance does not have a ParentProvider, it is
                    ' not a child in a hierarchy, and can be the RootProvider.
                Else
                    Return Me
                End If
            End Get
        End Property

        ' Implement the FindSiteMapNode method.
        Public Overrides Function FindSiteMapNode(ByVal rawUrl As String) As SiteMapNode
            ' Does the root node match the URL?
            If RootNode.Url = rawUrl Then
                Return RootNode
            Else
                Dim candidate As SiteMapNode = Nothing
                ' Retrieve the SiteMapNode that matches the URL.
                SyncLock Me
                    candidate = GetNode(siteMapNodes, rawUrl)
                End SyncLock
                Return candidate
            End If
        End Function 'FindSiteMapNode

        ' Implement the GetChildNodes method.
        Public Overrides Function GetChildNodes(ByVal node As SiteMapNode) As SiteMapNodeCollection
            Dim children As New SiteMapNodeCollection()
            ' Iterate through the ArrayList and find all nodes that have the specified node as a parent.
            SyncLock Me
                Dim i As Integer
                For i = 0 To childParentRelationship.Count - 1

                    Dim de As DictionaryEntry = CType(childParentRelationship(i), DictionaryEntry)
                    Dim nodeUrl As String = CType(de.Key, String)

                    Dim parent As SiteMapNode = GetNode(childParentRelationship, nodeUrl)

                    If Not (parent Is Nothing) AndAlso node.Url = parent.Url Then
                        ' The SiteMapNode with the Url that corresponds to nodeUrl
                        ' is a child of the specified node. Get the SiteMapNode for
                        ' the nodeUrl.
                        Dim child As SiteMapNode = FindSiteMapNode(nodeUrl)
                        If Not (child Is Nothing) Then
                            children.Add(CType(child, SiteMapNode))
                        Else
                            Throw New Exception("ArrayLists not in sync.")
                        End If
                    End If
                Next i
            End SyncLock
            Return children
        End Function 'GetChildNodes

        Protected Overrides Function GetRootNodeCore() As SiteMapNode
            Return RootNode
        End Function ' GetRootNodeCore()

        ' Implement the GetParentNode method.
        Public Overrides Function GetParentNode(ByVal node As SiteMapNode) As SiteMapNode
            ' Check the childParentRelationship table and find the parent of the current node.
            ' If there is no parent, the current node is the RootNode.
            Dim parent As SiteMapNode = Nothing
            SyncLock Me
                ' Get the Value of the node in childParentRelationship
                parent = GetNode(childParentRelationship, node.Url)
            End SyncLock
            Return parent
        End Function 'GetParentNode

        ' Implement the ProviderBase.Initialize method.
        ' Initialize is used to initialize the state that the Provider holds, but
        ' not actually build the site map.
        Public Overrides Sub Initialize(ByVal name As String, ByVal attributes As NameValueCollection)
            SyncLock Me
                MyBase.Initialize(name, attributes)
                simpleTextProviderName = name


                Dim cuoffice As CUOffice = System.Web.HttpContext.Current.Session("cuoffice")
                cCUID = cuoffice.cuid
                Dim member As Member = System.Web.HttpContext.Current.Session("member")
                execUser = member.memberType
                strSession = member.sessionNo

                siteMapNodes = New ArrayList()
                childParentRelationship = New ArrayList()
                userArray = New ArrayList()
                userArray.Add(ReturnDbParam("pc_cu_id", cCUID))
                userArray.Add(ReturnDbParam("pc_member_type", execUser))
                'userArray.Add(returndbparam("pn_session_no",strSession))
                FillMenus(userArray, "pkdb_web_menus.f_get_main_menu", menuLists)
                ' Build the site map in memory.
                LoadSiteMapFromStore()
            End SyncLock
        End Sub 'Initialize

        ' Private helper methods
        Private Function GetNode(ByVal list As ArrayList, ByVal url As String) As SiteMapNode
            Dim i As Integer
            For i = 0 To list.Count - 1
                Dim item As DictionaryEntry = CType(list(i), DictionaryEntry)
                If CStr(item.Key) = url Then
                    Return CType(item.Value, SiteMapNode)
                End If
            Next i
            Return Nothing
        End Function 'GetNode

        ' Get the URL of the currently displayed page.
        Private Function FindCurrentUrl() As String
            Try
                ' The current HttpContext.
                Dim currentContext As HttpContext = HttpContext.Current
                If Not (currentContext Is Nothing) Then
                    Return currentContext.Request.RawUrl
                Else
                    Throw New Exception("HttpContext.Current is Invalid")
                End If
            Catch e As Exception
                Throw New NotSupportedException("This provider requires a valid context.", e)
            End Try
        End Function 'FindCurrentUrl

        Protected Overridable Sub LoadSiteMapFromStore()
            'Dim pathToOpen As String
            SyncLock Me
                ' If a root node exists, LoadSiteMapFromStore has already
                ' been called, and the method can return.
                If Not (aRootNode Is Nothing) Then
                    Return
                Else
                    Try
                        If Not (menuLists Is Nothing) Then
                            If menuLists.Count > 0 Then

                                ' Clear the state of the collections and aRootNode
                                aRootNode = Nothing
                                siteMapNodes.Clear()
                                childParentRelationship.Clear()

                                ' Parse the file and build the site map
                                Dim s As String = ""
                                Dim nodeValues As String() = Nothing
                                Dim temp As SiteMapNode = Nothing

                                For Each menuEach In menuLists
                                    If Not menuEach Is Nothing Then
                                        ' Build the various SiteMapNode objects and add
                                        ' them to the ArrayList collections. The format used
                                        ' is: URL,TITLE,DESCRIPTION,PARENTURL

                                        temp = New SiteMapNode(Me, _
                                            menuEach.MenuID, _
                                            menuEach.navurl, _
                                            menuEach.title, _
                                            menuEach.tooltip)

                                        ' Is this a root node yet?
                                        If aRootNode Is Nothing AndAlso _
                                          (menuEach.parentID Is Nothing OrElse _
                                           menuEach.parentID = String.Empty) Then
                                            aRootNode = temp

                                            ' If not the root node, add the node to the various collections.
                                        Else

                                            siteMapNodes.Add(New DictionaryEntry(temp.Url, temp))

                                            ' The parent node has already been added to the collection.
                                            Dim parentNode As SiteMapNode = FindSiteMapNode(menuEach.purl)

                                            If Not (parentNode Is Nothing) Then
                                                childParentRelationship.Add(New DictionaryEntry(temp.Url, parentNode))
                                            Else
                                                Throw New Exception("Parent node not found for current node.")
                                            End If
                                        End If
                                    End If
                                Next menuEach

                            Else
                                Throw New Exception("No Menu Record Found.")
                            End If
                        Else
                            Throw New Exception("No Menu Record Found.")
                        End If
                    Finally
                    End Try
                End If
            End SyncLock
            Return
        End Sub 'LoadSiteMapFromStore
    End Class
End Namespace
0

Hi

Have you ever got an answer for your question? I have exactly the same problem.

Thanks,
Miri

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.