CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 1/20/2006 1:58:00 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 10 Views: 29 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
11 Items, 1 Pages 1 |< << Go >> >|
docluv
Asp.Net User
SiteMapProvder Only Providing the first node1/20/2006 1:58:00 AM

0/0

I am trying to finish up my own SQLSiteMapProvider based on Jeff Procise's Wicked Code Column.  It returns the first node, but nothing after that, unless it is a child of the first node (Home Page).

I even tried the following code:

_root = CreateSiteMapNodeFromDataReader(reader)

AddNode(_root, Nothing)

AddNode(New SiteMapNode(Me, "Test1", "textTools.aspx"), Nothing)

AddNode(New SiteMapNode(Me, "Test2", "textMonitoring.aspx"), Nothing)

and still only the First node.

Thanks


Chris Love
Dave Sussman
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/20/2006 9:33:44 AM

0/0

Get hold of the Contoso Provider Toolkit from MSDN. It provides a fully featured SQL site map provider.

Dave

docluv
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/20/2006 11:55:14 AM

0/0

That looks just like Jeff Procises code I translated into VB.  So that is not a help.

Here is the provider I translated from that code in C# to VB.  This is how it currently stands, I have a few items broken out trying to figure out why only the first node is getting passed to the menu controls referencing the data.  BTW, I have a page with a bread crumb, Menu and Treeview trying to figure this one out.  If I add a node with the first node as the parent, it shows up as a sub menu.  But I do not want that in this case, I reall need say the top 5 pages listed horizontally in the menu, then I will drop the sub-menus in.  Another thing, I added a few more fields to the sitemap database table, and I do not reference values in a datareader by the Index, I reference them by name.  This way I know I get the field I want.

 

Imports System.Web.Caching

Imports System.Data.Common

Imports Microsoft.VisualBasic

Imports System.Data.SqlClient

Imports System.Data

Imports System.Security.Permissions

Imports System.Collections

Imports System

Imports System.Collections.Generic

Imports System.Web.Configuration

Imports System.Configuration.Provider

<SqlClientPermission(SecurityAction.Demand, Unrestricted:=True)> _

Public Class SqlSiteMapProvider

Inherits StaticSiteMapProvider

'

Private _errmsg1 As String = "Missing node ID"

Private _errmsg2 As String = "Duplicate node ID"

Private _errmsg3 As String = "Missing parent ID"

Private _errmsg4 As String = "Invalid parent ID"

Private _errmsg5 As String = "Empty or missing connectionStringName"

Private _errmsg6 As String = "Missing connection string"

Private _errmsg7 As String = "Empty connection string"

Private _errmsg8 As String = "Invalid sqlCacheDependency"

Private _cacheDependencyName As String = "__SiteMapCacheDependency"

Private _connect As String

Private _database, _table As String

Private _2005dependency As Boolean = False

Private _nodes As New Dictionary(Of Integer, SiteMapNode)(16)

Private _root As SiteMapNode

Private _lock As New Object()

 

Public Overrides Sub Initialize(ByVal name As String, ByVal config As NameValueCollection)

' Verify parameters

If config Is Nothing Then

Throw New ArgumentNullException("config")

End If

If [String].IsNullOrEmpty(name) Then

name = "SqlSiteMapProvider"

End If

' Add a default "description" attribute to config if the

' attribute doesn't exist or is empty

If String.IsNullOrEmpty(config("description")) Then

config.Remove("description")

config.Add("description", "SQL site map provider")

End If

' Call the base class's Initialize method

MyBase.Initialize(name, config)

' Initialize _connect

Dim connect As String = config("connectionStringName")

If [String].IsNullOrEmpty(connect) Then

Throw New ProviderException("Could Not Initialize Connection String.")

End If

config.Remove("connectionStringName")

If WebConfigurationManager.ConnectionStrings(connect) Is Nothing Then

Throw New ProviderException("Problem with Web Configuration Manager Connection Strings are Null or Empty.")

End If

_connect = WebConfigurationManager.ConnectionStrings(connect).ConnectionString

If [String].IsNullOrEmpty(_connect) Then

Throw New ProviderException("Problem with Connection String Null or Emtpy.")

End If

' Initialize SQL cache dependency info

Dim dependency As String = config("sqlCacheDependency")

If Not [String].IsNullOrEmpty(dependency) Then

If [String].Equals(dependency, "CommandNotification", StringComparison.InvariantCultureIgnoreCase) Then

SqlDependency.Start(_connect)

_2005dependency = True

Else

' If not "CommandNotification", then extract

' database and table names

Dim info As String() = dependency.Split(New Char() {":"c})

If info.Length <> 2 Then

Throw New ProviderException("No Dependancy Set.")

End If

_database = info(0)

_table = info(1)

End If

config.Remove("sqlCacheDependency")

End If

' Throw an exception if unrecognized attributes remain

If config.Count > 0 Then

Dim attr As String = config.GetKey(0)

If Not [String].IsNullOrEmpty(attr) Then

Throw New ProviderException("Unrecognized attribute: " + attr)

End If

End If

End Sub 'Initialize

 

Public Overrides Function BuildSiteMap() As SiteMapNode

SyncLock _lock

' Return immediately if this method has been called before

If Not (_root Is Nothing) Then

Return _root

End If

' Query the database for site map nodes

Dim connection As New SqlConnection(_connect)

Try

Dim command As New SqlCommand("proc_GetSiteMap", connection)

command.CommandType = CommandType.StoredProcedure

' Create a SQL cache dependency if requested

Dim dependency As SqlCacheDependency = Nothing

If _2005dependency Then

dependency = New SqlCacheDependency(command)

Else

If Not [String].IsNullOrEmpty(_database) And Not [String].IsNullOrEmpty(_table) Then

dependency = New SqlCacheDependency(_database, _table)

End If

End If

connection.Open()

Dim reader As SqlDataReader = command.ExecuteReader()

If reader.Read() Then

' Create the root SiteMapNode and add it to site map

_root = CreateSiteMapNodeFromDataReader(reader)

AddNode(_root, Nothing)

AddNode(New SiteMapNode(Me, "Test1", "textTools.aspx"), Nothing)

AddNode(New SiteMapNode(Me, "Test2", "textMonitoring.aspx"), Nothing)

' Build a tree of SiteMapNodes under the root node

While reader.Read()

' Create another site map node and add it

AddNode(CreateSiteMapNodeFromDataReader(reader), Nothing)

' AddNode(CreateSiteMapNodeFromDataReader(reader), _

' GetParentNodeFromDataReader(reader))

End While

' Use the SQL cache dependency

If Not (dependency Is Nothing) Then

HttpRuntime.Cache.Insert(_cacheDependencyName, New Object(), _

dependency, Cache.NoAbsoluteExpiration, _

Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, _

New CacheItemRemovedCallback(AddressOf OnSiteMapChanged))

End If

End If

Finally

connection.Dispose()

End Try

' Return the root SiteMapNode

Return _root

End SyncLock

End Function 'BuildSiteMap

 

Protected Overrides Function GetRootNodeCore() As SiteMapNode

SyncLock _lock

Return BuildSiteMap()

End SyncLock

End Function 'GetRootNodeCore

Public Function CreateSiteMapNodeFromDataReader(ByVal reader As SqlDataReader) As SiteMapNode

' Make sure the node ID is present

If IsDBNull(reader("ID")) Then

Throw New ProviderException(_errmsg1)

End If

' Get the node ID from the DataReader

Dim id As Integer = Convert.ToInt32(reader("ID"))

' Make sure the node ID is unique

If (_nodes.ContainsKey(id)) Then

Throw New ProviderException(_errmsg2)

End If

' Get title, URL, description, and roles from the DataReader

Dim title As String

If IsDBNull(reader("Title")) Then

title = String.Empty

Else

title = reader("Title").ToString.Trim()

End If

Dim url As String

If IsDBNull(reader("Url")) Then

url = String.Empty

Else

url = reader("Url").ToString.Trim()

End If

Dim description As String

If IsDBNull(reader("description")) Then

description = String.Empty

Else

description = reader("description").ToString.Trim()

End If

Dim roles As String

If IsDBNull(reader("roles")) Then

roles = String.Empty

Else

roles = reader("roles").ToString.Trim()

End If

' If roles were specified, turn the list into a string array

Dim rolelist() As String = Nothing

If Not String.IsNullOrEmpty(roles) Then

rolelist = roles.Split(";")

End If

' Create a SiteMapNode

Dim node As New SiteMapNode(Me, id.ToString(), url, title, _

description, rolelist, Nothing, Nothing, Nothing)

' node.ParentNode = GetParentNodeFromDataReader(reader)

' Record the node in the _nodes dictionary

_nodes.Add(id, node)

' Return the node

Return node

End Function

Public Function GetParentNodeFromDataReader(ByVal reader As SqlDataReader) As SiteMapNode

' Make sure the parent ID is present

If IsDBNull(reader("Parent")) Then

Throw New ProviderException(_errmsg3)

End If

' Get the parent ID from the DataReader

Dim pid As Integer = Convert.ToInt32(reader("Parent"))

' Make sure the parent ID is valid

If IsNothing(_nodes.ContainsKey(pid)) Then

Throw New ProviderException(_errmsg4)

End If

' Return the parent SiteMapNode

If pid > 0 Then

Return _nodes(pid)

Else

Return Nothing

End If

End Function

 

Public Sub OnSiteMapChanged(ByVal key As String, ByVal item As Object, ByVal reason As CacheItemRemovedReason)

SyncLock _lock

If (key = _cacheDependencyName And reason = CacheItemRemovedReason.DependencyChanged) Then

' Refresh the site map

Clear()

_nodes.Clear()

_root = Nothing

End If

End SyncLock

End Sub

 

End Class 'SqlSiteMapProvider

 


Chris Love
docluv
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/20/2006 11:06:53 PM

0/0

Is it just me or are all the examples I find on a Custom SiteMapProvider setup only to return one node and its children, like this:

RootNode
-ChildNode1
-ChildNode2
-ChildeNode3

No like this:

RootNode1                 RootNode2                RootNode3
-ChildNode1                 -ChildNode21           -ChildeNode31
-ChildNode2                 -ChildNode22           -ChildeNode32
-ChildeNode3                                                -ChildeNode33

I can find any examples that add sibling to the root.  This is the problem.  I know the nodes are getting added because I put a SiteMapPath and as I go to the pages I added the name is displayed.


Chris Love
docluv
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/21/2006 9:14:03 AM

0/0

Evidently you can only have one node in a site map.  This comes straight from the documentation of the XmlSiteMapProvider Class, ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref12/html/T_System_Web_XmlSiteMapProvider.htm.

<siteMap>
  <siteMapNode title="RootNode" description="This is the root node of the site map. There can be only one root node." url="Page1.aspx" >
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page2.aspx">
      <siteMapNode title="ChildOfChildNode" description="SiteMapNode objects can be nested to any level." url="Page3.aspx"/>
    </siteMapNode>
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page4.aspx"/>
  </siteMapNode>
</siteMap>
I think it is sort of hard to call something a sitemap provider when in only supplies the map of one item of the navigation.  I suppose this would be useful in defining a context menu, but nothing else.  What a shame, this is a useless class for a web site to have.

Chris Love
docluv
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/21/2006 10:11:53 AM

0/0

OK, so that was a litle harsh.  I think I have it figured out now.  The SiteMap is not totally useless, just for site navigation.  What it is realy menat for is an easy way to fill in a treeview control to display all the pages on a site, or at least the ones entered in the site map.

I am going to just crreate my own menu provider of sorts.  I just wish I would have never been under the impression that the SiteMapProvider could be used with the menu control to provide site navigation.  That was a lot of time I and others have wasted.  So as a suggestion for the furutre to all our Microsoft guys, please remove any samples of the menu control interfacing with the SiteMapProvider at all, it is very, very misleading.


Chris Love
Dave Sussman
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/21/2006 10:45:59 AM

0/0

Yes you can only have one root node in the sitemap file, but that isn't actually limiting - it still works perfectly well for menus, just set the StaticDisplayLevels property to 2 so the root node plus its children are always displayed.

I haven't had time to look into why your code, or a C# equivalent of the provider toolkit one, don't seem to work, but I've written a database provider that works with both the TreeView and menu controls. This was part of a talk I did on navigation, so you can get the provider and the slides here.

Dave

docluv
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/21/2006 2:04:38 PM

0/0

Thanks for your response.  Finally after about 6 hours of writing code, debugiing and reading stuff, it finally displays all the top level menu items.  However, I just think this seems so counter-intuative.  Shouldn't a site map allow siblings at any level?

On to the next task, I think I will have issues there as well.  I know I will have a need to multiple references to a url in my site map.  But evidently this is not allowed.  It is sort of a Magic HyperRedirect Module solved issue from DotNetNuke.  That will be another thread if I can not figure that one out. =>.

BTW, how do you make the Root Siblings display that way on a TreeView?  I know as soon as I use this for a sitemap, I will be asked to do it that way.  There is not StaticDisplayLevels property there.


Chris Love
Dave Sussman
Asp.Net User
Re: SiteMapProvder Only Providing the first node1/21/2006 2:28:57 PM

0/0

I agree actually, having the site map restricted to a single root node is counter to what we learn about XML, but the reason for it is that the sitemap architecture is based around having a root node. You can also hide the root node when displaying the menu, so only the siblings appear.

I've also complained about URLs being unique, but there is also a reason for this. When finding nodes, the URL is used, so what would happen if two nodes had the same URL, which would be returned? You can of course change this beehaviour by inheriting from SiteMapProvider instead of StaticSiteMapProvider; this is what I did in my provider, but it is more work.

Not too sure about displaying on the treeview - I rarely use it for menus, preferring the menu or my own menu control.

Dave

FanOfAtlas
Asp.Net User
Re: SiteMapProvder Only Providing the first node9/7/2006 2:41:17 AM

0/0

BTW what is the change that you made to make it work. Can you please post the code.

Shawn 


-Shaun
tkdtaylor
Asp.Net User
Re: SiteMapProvder Only Providing the first node9/12/2006 2:36:48 PM

0/0

I found a good link that shows how to control which levels are shown from your sitemap: http://msdn2.microsoft.com/en-us/library/16yk5dby.aspx

Basically you just have to set the ShowStartingNode to False in the properties of your datasource.

11 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
SiteMapProvder Only Providing the first node - ASP.NET Forums This is how it currently stands, I have a few items broken out trying to figure out why only the first node is getting passed to the menu ...
patterns & practices Web Client Software Factory - Discussions Only works good when I used the .dll assemblies of the C:\Program ..... First post: que0x wrote: Hi Folks, I need to hide node according to User Role, ...... Actually, your directing me to a book was greater than providing the answer. ...... best way to use the sitemapprovder, and if I should be using it at all. ...
Sitemap error: Could not find the sitemap node with URL - ng.asp ... help with tree view / site map · menu control: error 0.cells is null or not an object · sitemapprovder only providing the first node ...
Search Engine Sprider/Crawler - ng.asp-net-forum ... sitemapprovder only providing the first node · variables.... layout issue · database to menu · asp.net 2.0 menu - click on row and text! ...




Search This Site:










tree view

specifying masterpages dynamically using pagebasetype in web.config

can't reach control placed in loginview

onmenuitemclick causing postback all the time

can we use user controls in master page ?

can i load an aspx into a contentplaceholder programatically?

how to collapse a databound treeview?

skinid error

highlight root node of menu when browsing child node

problems with stylesheets in master pages...

syle sheet not taken up

scroll position to the center of the screen when user clicks the new button in a formview control in asp.net 2.0

site map created is changed upon uploading to free host

hi, can i set a different masterpage to a certain webform dynamically?

master page drop menu overlap problem

one treeview for different users?

creating page specific menus from site nodes

custom errors with masterpage question

need help with layout, how do i get nice forms without the grid?

treeview issue

sqlsitemapprovider role issue

dynamic menu bug in safari

do not cache login-details in masterpage

error on the preinit method of the page

using sitemappath

accessing parent master page function from child master page

can any one help me how to use tree view

why default page is always loaded when visiting other pages?

securitytrimming and sitemappath

wizard control

  Privacy | Contact Us
All Times Are GMT