Hi JJ,
Okay, I think I understand. Try the following code and see if it approaches
what you're after? You would need to point the Flash to the file
FlashSiteMap.ashx as if it were an XML file 'cause that's what it outputs.
Let us know?
Ken
Microsoft MVP [ASP.NET]
kj***@hotmail.com
<%@ WebHandler Language="VB" Class="FlashSiteMap" %>
' FlashSiteMap.ashx
' by Ken Cox [MVP]
' Adapted from Stephen Walther's code
' in ASP.NET 2.0 Unleashed, Chapter 18
Imports System
Imports System.Web
Imports System.Xml
Imports System.Text
Imports System.IO
Public Class FlashSiteMap
Implements IHttpHandler
' Gets the sitemap nodes and renders them
' via a handler to XML
Private writer_xml As XmlWriter
Public Sub ProcessRequest _
(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "text/xml"
Dim settings As New XmlWriterSettings()
settings.Encoding = Encoding.UTF8
settings.Indent = True
writer_xml = XmlWriter.Create _
(context.Response.OutputStream, settings)
writer_xml.WriteStartDocument()
writer_xml.WriteStartElement _
("Flashnodes", "http://pp/schemas/flashmap")
' Add root node
AddUrl(SiteMap.RootNode)
' Add all other nodes
Dim nodes As SiteMapNodeCollection = _
SiteMap.RootNode.GetAllNodes()
For Each node As SiteMapNode In nodes
AddUrl(node)
Next
writer_xml.WriteEndElement()
writer_xml.WriteEndDocument()
writer_xml.Flush()
End Sub
Private Sub AddUrl(ByVal node As SiteMapNode)
' Open url tag
writer_xml.WriteStartElement("siteMapNode")
' Write location
writer_xml.WriteStartElement("url")
writer_xml.WriteString(node.Url)
writer_xml.WriteEndElement()
' Write description
writer_xml.WriteStartElement("description")
writer_xml.WriteString(node.Description)
writer_xml.WriteEndElement()
writer_xml.WriteStartElement("title")
writer_xml.WriteString(node.Title)
writer_xml.WriteEndElement()
' Close tag
writer_xml.WriteEndElement()
End Sub
Public ReadOnly Property IsReusable() _
As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
"JJ" <ab*@xyz.comwrote in message
news:eW****************@TK2MSFTNGP05.phx.gbl...
I am constructing a Flash menu system that builds its content based on the
web.sitemap file. How Flash does that here is of no importance - it just
needs URL access to the XML sitemap file.
However, due to the built-in security, the server does not allow the
'.sitemap' file to be accessed directly.
I am therefore writing a handler to allow access to the file. I could do
this easily by reading in the physical file and outputting it.
But if I was to use roles, I did not want the Flash menu to have access to
nodes which had roles which were more privileged than the current user.
I then came across 'security trimming', which if enabled, filters out the
nodes that the user should see, but only when you use certain commands to
access the web.sitemap nodes.
Reading the physical file was bypassing security trimming, and so I'd have
had to hand code the roles filtering. I noticed that when I copied the
current web.sitemap into a sitenodemapcollection it filtered out any nodes
the user wasn't meant to see. This would save me having to come up with code
to parse the web.sitemap file and do the filtering myself.
But, I am not sure how I output that collection in a form, presumably of:
Dim writer As XmlTextWriter = New XmlTextWriter(response.OutputStream,
Encoding.UTF8)
Currently I am having to iterate through the web.sitemap file in the handler
and manually check if there is a role string present and if
currentuser.IsInRole(rolestring). But its messy and I want to use the built
in security trimming.
I hope I haven't made that too confusing. I'm a bit new to asp.net,
JJ
"Ken Cox [Microsoft MVP]" <BA**********@newsgroups.nospamwrote in message
news:eY**************@TK2MSFTNGP03.phx.gbl...
Could you clarify what you need to do? The SiteMapPath control reads from
web.sitemap which is already an XML file.
Ken
Microsoft MVP [ASP.NET]
"JJ" <ab*@xyz.comwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
>How can I get a SiteMapNodeCollection to output as an XML file?