カスタム サイトマップを作成しようとしています このサイトのコードを調べています
http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site
可能な限りvb.netに変換しました
ここに私のコードがあります
Partial Class Main
Inherits StaticSiteMapProvider
Dim conn As New ConnectionVB
Dim _rootNode As SiteMapNode = Nothing
Dim _siteMapFileName As String
Dim SiteMapNodeName As String = "siteMapNode"
Public Sub DynamicSiteMapProvider()
End Sub
Public Shadows Function RootNode() As SiteMapNode
Return BuildSiteMap()
End Function
Public Overrides Sub Initialize(name As String, attributes As NameValueCollection)
//Me.Initialize(name, attributes)
_siteMapFileName = attributes("siteMapFile")
End Sub
Protected Overrides Function GetRootNodeCore() As SiteMapNode
Return RootNode()
End Function
Protected Overrides Sub clear()
SyncLock Me
_rootNode = Nothing
//Me.clear()
End SyncLock
End Sub
Public Overrides Function BuildSiteMap() As SiteMapNode
SyncLock Me
If _rootNode Is Nothing Then
clear()
Dim siteMapXml As XmlDocument = LoadSiteMapXml()
Dim rootElement As XmlElement = CType(siteMapXml.GetElementsByTagName(SiteMapNodeName)(0), XmlElement)
AddDynamicNodes(rootElement)
GenerateSiteMapNodes(rootElement)
End If
End SyncLock
Return _rootNode
End Function
Private Function LoadSiteMapXml() As XmlDocument
Dim siteMapXml As XmlDocument = New XmlDocument()
siteMapXml.Load(AppDomain.CurrentDomain.BaseDirectory + _siteMapFileName)
Return siteMapXml
End Function
Protected Sub AddDynamicNodes(rootElement As XmlElement)
Dim teams As XmlElement = AddDynamicChildElement(rootElement, "", "FootballTeams", "List of football team")
End Sub
Protected Function AddDynamicChildElement(parentElement As XmlElement, url As String, title As String, description As String) As XmlElement
Dim childElement As XmlElement = parentElement.OwnerDocument.CreateElement(SiteMapNodeName)
childElement.SetAttribute("url", url)
childElement.SetAttribute("title", title)
childElement.SetAttribute("description", description)
parentElement.AppendChild(childElement)
Return childElement
End Function
Protected Sub GenerateSiteMapNodes(rootElement As XmlElement)
_rootNode = GetSiteMapNodeFromElement(rootElement)
AddNode(_rootNode)
CreateChildNodes(rootElement, _rootNode)
End Sub
Protected Sub CreateChildNodes(parentElement As XmlElement, parentNode As SiteMapNode)
For Each XmlElement As XmlNode In parentElement.ChildNodes
If XmlElement.Name = SiteMapNodeName Then
Dim childNode As SiteMapNode = GetSiteMapNodeFromElement(CType(XmlElement, XmlElement))
AddNode(childNode, parentNode)
CreateChildNodes(CType(XmlElement, XmlElement), childNode)
End If
Next
End Sub
Protected Function GetSiteMapNodeFromElement(rootElement As XmlElement) As SiteMapNode
Dim newSiteMapNode As SiteMapNode
Dim url As String = rootElement.GetAttribute("url")
Dim title As String = rootElement.GetAttribute("title")
Dim description As String = rootElement.GetAttribute("description")
newSiteMapNode = New SiteMapNode(Me, (url + title).GetHashCode().ToString(), url, title, description)
Return newSiteMapNode
End Function
End Class
このようなエラーが発生しました
System.ArgumentException: Provider name cannot be null or empty.
誰かが私を助けることができるこのエラーの原因がわかりません??
すべての助けに感謝します
ありがとう
PS : 私の英語がめちゃくちゃだったらごめんなさい