Re: Output SiteMapNodeCollection as an XML file?



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]
kjopc@xxxxxxxxxxx


<%@ 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" <abc@xxxxxxx> wrote in message
news:eWK%23KKZpGHA.1140@xxxxxxxxxxxxxxxxxxxxxxx
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]" <BANSPAMkjopc@xxxxxxxxxxxxxxxxx> wrote in message
news:eYxzuFVpGHA.2400@xxxxxxxxxxxxxxxxxxxxxxx

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" <abc@xxxxxxx> wrote in message
news:ucbb0RNpGHA.3600@xxxxxxxxxxxxxxxxxxxxxxx
How can I get a SiteMapNodeCollection to output as an XML file?






.



Relevant Pages

  • Re: Output SiteMapNodeCollection as an XML file?
    ... **Basically I need a way of making an identical copy of the sitemap, ... XML reader it looks at the physical file and therefore bypasses security ... Reading the physical file was bypassing security trimming, ... code to parse the web.sitemap file and do the filtering myself. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Web.sitemap and Flash
    ... I have realised now what the security problem is.... ... Flash to diplay menu's based on the web.sitemap contents.: ... If the .sitemap is being used by an ASP.NET application, ... I suspect therefore that this is a result of the browser not knowing ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Web.sitemap and Flash
    ... I ended up using a handler to allow read access to the web.sitemap file. ... When I then tell flash to use the handler in stead of the web.sitemap file ... If the .sitemap is being used by an ASP.NET application, ... I suspect therefore that this is a result of the browser not knowing ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Web.sitemap and Flash
    ... I think that the reason is that ASP.NET protects some files from direct ... To change sitemap to xml or not is your decision. ... it is not OK then you should decide if you want flash to use this file. ... I suspect therefore that this is a result of the browser not knowing what ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Web.sitemap and Flash
    ... renaming the sitemap file will make it unavailable to the app. ... xml files by default are not protected so you can view it from client. ... I get an error in Flash when it trys to open this file using standard Flash commands. ... I suspect therefore that this is a result of the browser not knowing what a '.sitemap' file is??? ...
    (microsoft.public.dotnet.framework.aspnet)

Loading