asked on
ASKER
If reader.IsDBNull(url) Then
node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), "", reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
Else
node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), reader.GetString(url), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
End If
ASKER
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Web.Configuration
Public Class SqlSiteMapProvider
Inherits StaticSiteMapProvider
Shared ReadOnly _errmsg1 As String = "Missing connectionStringName attribute"
Shared ReadOnly _errmsg2 As String = "Duplicate node ID"
Private _root As SiteMapNode = Nothing
Private _connect As String
Public Overloads Overrides Sub Initialize(ByVal name As String, ByVal attributes As NameValueCollection)
MyBase.Initialize(name, attributes)
If attributes Is Nothing Then
Throw New System.Configuration.ConfigurationErrorsException(_errmsg1)
End If
_connect = attributes("connectionStringName")
If [String].IsNullOrEmpty(_connect) Then
Throw New System.Configuration.ConfigurationErrorsException(_errmsg1)
End If
End Sub
<System.Runtime.CompilerServices.MethodImpl(Runtime.CompilerServices.MethodImplOptions.Synchronized)> _
Public Overloads Overrides Function BuildSiteMap() As SiteMapNode
' Return immediately if this method has been called before
If _root IsNot Nothing Then
Return _root
End If
' Create a dictionary for temporary node storage and lookup
Dim nodes As New Dictionary(Of Integer, SiteMapNode)(16)
' Query the database for site map nodes
Dim connection As New SqlConnection(WebConfigurationManager.ConnectionStrings(_connect).ConnectionString)
Try
connection.Open()
Dim command As New SqlCommand("SELECT ID, Title, Description, Url, " + "Roles, Parent FROM SiteMap ORDER BY ID", connection)
Dim reader As SqlDataReader = command.ExecuteReader()
Dim id As Integer = reader.GetOrdinal("ID")
Dim url As Integer = reader.GetOrdinal("Url")
Dim title As Integer = reader.GetOrdinal("Title")
Dim desc As Integer = reader.GetOrdinal("Description")
Dim roles As Integer = reader.GetOrdinal("Roles")
Dim parent As Integer = reader.GetOrdinal("Parent")
If reader.Read() Then
' Create the root SiteMapNode
_root = New SiteMapNode(Me, reader.GetInt32(id).ToString(), IIf(reader.IsDBNull(url), Nothing, reader.GetString(url)), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
If Not reader.IsDBNull(roles) Then
Dim rolenames As String = reader.GetString(roles).Trim()
If Not [String].IsNullOrEmpty(rolenames) Then
Dim rolelist As String() = rolenames.Split(New Char() {","c, ";"c}, 512)
_root.Roles = rolelist
End If
End If
' Add "*" to the roles list if no roles are specified
If _root.Roles Is Nothing Then
_root.Roles = New String() {"*"}
End If
' Record the root node in the dictionary
If nodes.ContainsKey(reader.GetInt32(id)) Then
Throw New System.Configuration.ConfigurationErrorsException(_errmsg2)
End If
nodes.Add(reader.GetInt32(id), _root)
' Add the node to the site map
AddNode(_root, Nothing)
' Build a tree of SiteMapNodes underneath the root
While reader.Read()
'Dim node As New SiteMapNode(Me, reader.GetInt32(id).ToString(), IIf(reader.IsDBNull(url), Nothing, reader.GetString(url)), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
Dim node As SiteMapNode = Nothing
If reader.IsDBNull(url) Then
node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), Nothing, reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
Else
node = New SiteMapNode(Me, reader.GetInt32(id).ToString(), reader.GetString(url), reader.GetString(title), IIf(reader.IsDBNull(desc), Nothing, reader.GetString(desc)))
End If
If Not reader.IsDBNull(roles) Then
Dim rolenames As String = reader.GetString(roles).Trim()
If Not [String].IsNullOrEmpty(rolenames) Then
Dim rolelist As String() = rolenames.Split(New Char() {","c, ";"c}, 512)
node.Roles = rolelist
End If
End If
' If the node lacks roles information,
' "inherit" that information from its parent
Dim parentnode As SiteMapNode = nodes(reader.GetInt32(parent))
If node.Roles Is Nothing Then
node.Roles = parentnode.Roles
End If
' Record the node in the dictionary
If nodes.ContainsKey(reader.GetInt32(id)) Then
Throw New System.Configuration.ConfigurationErrorsException(_errmsg2)
End If
nodes.Add(reader.GetInt32(id), node)
' Add the node to the site map
AddNode(node, parentnode)
End While
End If
Finally
connection.Close()
End Try
' Return the root SiteMapNode
Return _root
End Function
Protected Overloads Overrides Function GetRootNodeCore() As SiteMapNode
BuildSiteMap()
Return _root
End Function
End Class
ASKER
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY
Andrew