Home All Groups Group Topic Archive Search About
Author
11 Jun 2005 10:56 PM
Mark Parter
I have a master page which contains a Menu control and a SiteMapPath control,
both are bound to the same web.sitemap XML file. Say I have 2 pages, Page 1
and Page 2. Now Page 2 can only be accessed after selecting some information
on Page 1 (using a CrossPagePostback). When the user get's to Page 2, the
SiteMapPath control fails to render, obviously because Page 2 isn't in the
web.sitemap file.

If I put Page 2 in the web.sitemap file, it then get's rendered in the Menu
control, which I don't want. So, is there any way to "hide" certain nodes in
a web.sitemap file from the Menu control?

Or is there anyway I can have the SiteMapPath control render properly on
Page 2 whilst not showing it in the Menu control to the user?

Author
12 Jun 2005 1:01 AM
Brock Allen
You're going to have to create a custom SiteMapProvider and override the
IsAccessibleToUser method to provide your custom display logic. The easiest
way would be to derive from the existing XmlSiteMapProvider. Fredrik has
some related sample code:

http://fredrik.nsquared2.com/viewpost.aspx?PostID=272&showfeedback=true

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> I have a master page which contains a Menu control and a SiteMapPath
> control, both are bound to the same web.sitemap XML file. Say I have 2
> pages, Page 1 and Page 2. Now Page 2 can only be accessed after
> selecting some information on Page 1 (using a CrossPagePostback). When
> the user get's to Page 2, the SiteMapPath control fails to render,
> obviously because Page 2 isn't in the web.sitemap file.
>
> If I put Page 2 in the web.sitemap file, it then get's rendered in the
> Menu control, which I don't want. So, is there any way to "hide"
> certain nodes in a web.sitemap file from the Menu control?
>
> Or is there anyway I can have the SiteMapPath control render properly
> on Page 2 whilst not showing it in the Menu control to the user?
>
Are all your drivers up to date? click for free checkup

Author
12 Jun 2005 10:52 AM
Mark Parter
Thanks for the link.

OK, I've tried to create a class inheriting the StaticSiteMapProvider but
only overriding the IsAccessibleToUser method. However, I keep getting a
'Cannot create an abstract class' when I try to run my app.

Imports Microsoft.VisualBasic

Namespace AdamSmithCollege.Web

    Public MustInherit Class CustomSiteMapProvider
        Inherits SiteMapProvider

        Public Overrides Function IsAccessibleToUser(ByVal context As
HttpContext, ByVal node As SiteMapNode) As Boolean
            If node Is Nothing Then
                Throw New ArgumentNullException("node")
            End If

            If context Is Nothing Then
                Throw New ArgumentNullException("context")
            End If

            If Not Me.SecurityTrimmingEnabled Then
                Return True
            End If

            If (Not node.Roles Is Nothing) And (node.Roles.Count > 0) Then
                Dim role As String
                For Each role In node.Roles
                    If Not String.Equals(role, "*",
StringComparison.InvariantCultureIgnoreCase) Then
                        Continue For
                    End If

                    Return True
                Next
            End If

            Return False
        End Function
    End Class
End Namespace

    <siteMap defaultProvider="CustomSiteMapProvider" enabled="true">
      <providers>
        <add name="XmlSiteMapProvider"
        <add name="CustomSiteMapProvider"
         description="This provider overrides the IsAccessibleToUser method."
         type="ASC.Web.CustomSiteMapProvider"
         securityTrimmingEnabled="true"
         siteMapFile="Web.sitemap" />
      </providers>
    </siteMap>

Show quoteHide quote
"Brock Allen" wrote:

> You're going to have to create a custom SiteMapProvider and override the
> IsAccessibleToUser method to provide your custom display logic. The easiest
> way would be to derive from the existing XmlSiteMapProvider. Fredrik has
> some related sample code:
>
> http://fredrik.nsquared2.com/viewpost.aspx?PostID=272&showfeedback=true
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > I have a master page which contains a Menu control and a SiteMapPath
> > control, both are bound to the same web.sitemap XML file. Say I have 2
> > pages, Page 1 and Page 2. Now Page 2 can only be accessed after
> > selecting some information on Page 1 (using a CrossPagePostback). When
> > the user get's to Page 2, the SiteMapPath control fails to render,
> > obviously because Page 2 isn't in the web.sitemap file.
> >
> > If I put Page 2 in the web.sitemap file, it then get's rendered in the
> > Menu control, which I don't want. So, is there any way to "hide"
> > certain nodes in a web.sitemap file from the Menu control?
> >
> > Or is there anyway I can have the SiteMapPath control render properly
> > on Page 2 whilst not showing it in the Menu control to the user?
> >
>
>
>
>
Author
12 Jun 2005 2:37 PM
Brock Allen
You've marked your class as "MustInherit" which means you can't create an
instance of it. To use the functionality a further dervived class is necessary.
I suspect you didn't intend this. Just remove the keyword.

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> Thanks for the link.
>
> OK, I've tried to create a class inheriting the StaticSiteMapProvider
> but only overriding the IsAccessibleToUser method. However, I keep
> getting a 'Cannot create an abstract class' when I try to run my app.
>
> Imports Microsoft.VisualBasic
>
> Namespace AdamSmithCollege.Web
>
> Public MustInherit Class CustomSiteMapProvider
> Inherits SiteMapProvider
> Public Overrides Function IsAccessibleToUser(ByVal context As
> HttpContext, ByVal node As SiteMapNode) As Boolean
> If node Is Nothing Then
> Throw New ArgumentNullException("node")
> End If
> If context Is Nothing Then
> Throw New ArgumentNullException("context")
> End If
> If Not Me.SecurityTrimmingEnabled Then
> Return True
> End If
> If (Not node.Roles Is Nothing) And (node.Roles.Count > 0)
> Then
> Dim role As String
> For Each role In node.Roles
> If Not String.Equals(role, "*",
> StringComparison.InvariantCultureIgnoreCase) Then
> Continue For
> End If
> Return True
> Next
> End If
> Return False
> End Function
> End Class
> End Namespace
> <siteMap defaultProvider="CustomSiteMapProvider" enabled="true">
> <providers>
> <add name="XmlSiteMapProvider"
> <add name="CustomSiteMapProvider"
> description="This provider overrides the IsAccessibleToUser
> method."
> type="ASC.Web.CustomSiteMapProvider"
> securityTrimmingEnabled="true"
> siteMapFile="Web.sitemap" />
> </providers>
> </siteMap>
> "Brock Allen" wrote:
>
>> You're going to have to create a custom SiteMapProvider and override
>> the IsAccessibleToUser method to provide your custom display logic.
>> The easiest way would be to derive from the existing
>> XmlSiteMapProvider. Fredrik has some related sample code:
>>
>> http://fredrik.nsquared2.com/viewpost.aspx?PostID=272&showfeedback=tr
>> ue
>>
>> -Brock
>> DevelopMentor
>> http://staff.develop.com/ballen
>>> I have a master page which contains a Menu control and a SiteMapPath
>>> control, both are bound to the same web.sitemap XML file. Say I have
>>> 2 pages, Page 1 and Page 2. Now Page 2 can only be accessed after
>>> selecting some information on Page 1 (using a CrossPagePostback).
>>> When the user get's to Page 2, the SiteMapPath control fails to
>>> render, obviously because Page 2 isn't in the web.sitemap file.
>>>
>>> If I put Page 2 in the web.sitemap file, it then get's rendered in
>>> the Menu control, which I don't want. So, is there any way to "hide"
>>> certain nodes in a web.sitemap file from the Menu control?
>>>
>>> Or is there anyway I can have the SiteMapPath control render
>>> properly on Page 2 whilst not showing it in the Menu control to the
>>> user?
>>>
Author
12 Jun 2005 3:29 PM
Mark Parter
Hi Brock,

Ooops, never saw that in there!

When I remove the 'MustInherit', I am then told that I must override;

FindSiteMapNode
GetChildNodes
GetParentNode
GetRootNodeCore

I then tried to inherit the XmlSiteMapProvider as this allowed me to only
override the IsAccessibleToUser, but it didn't seem to work as expected.

In the meantime, I've cheated by having 2 sitemaps, 1 for the menu and one
for the SiteMap Control (breadcrumbs).

Show quoteHide quote
"Brock Allen" wrote:

> You've marked your class as "MustInherit" which means you can't create an
> instance of it. To use the functionality a further dervived class is necessary.
> I suspect you didn't intend this. Just remove the keyword.
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
> > Thanks for the link.
> >
> > OK, I've tried to create a class inheriting the StaticSiteMapProvider
> > but only overriding the IsAccessibleToUser method. However, I keep
> > getting a 'Cannot create an abstract class' when I try to run my app.
> >
> > Imports Microsoft.VisualBasic
> >
> > Namespace AdamSmithCollege.Web
> >
> > Public MustInherit Class CustomSiteMapProvider
> > Inherits SiteMapProvider
> > Public Overrides Function IsAccessibleToUser(ByVal context As
> > HttpContext, ByVal node As SiteMapNode) As Boolean
> > If node Is Nothing Then
> > Throw New ArgumentNullException("node")
> > End If
> > If context Is Nothing Then
> > Throw New ArgumentNullException("context")
> > End If
> > If Not Me.SecurityTrimmingEnabled Then
> > Return True
> > End If
> > If (Not node.Roles Is Nothing) And (node.Roles.Count > 0)
> > Then
> > Dim role As String
> > For Each role In node.Roles
> > If Not String.Equals(role, "*",
> > StringComparison.InvariantCultureIgnoreCase) Then
> > Continue For
> > End If
> > Return True
> > Next
> > End If
> > Return False
> > End Function
> > End Class
> > End Namespace
> > <siteMap defaultProvider="CustomSiteMapProvider" enabled="true">
> > <providers>
> > <add name="XmlSiteMapProvider"
> > <add name="CustomSiteMapProvider"
> > description="This provider overrides the IsAccessibleToUser
> > method."
> > type="ASC.Web.CustomSiteMapProvider"
> > securityTrimmingEnabled="true"
> > siteMapFile="Web.sitemap" />
> > </providers>
> > </siteMap>
> > "Brock Allen" wrote:
> >
> >> You're going to have to create a custom SiteMapProvider and override
> >> the IsAccessibleToUser method to provide your custom display logic.
> >> The easiest way would be to derive from the existing
> >> XmlSiteMapProvider. Fredrik has some related sample code:
> >>
> >> http://fredrik.nsquared2.com/viewpost.aspx?PostID=272&showfeedback=tr
> >> ue
> >>
> >> -Brock
> >> DevelopMentor
> >> http://staff.develop.com/ballen
> >>> I have a master page which contains a Menu control and a SiteMapPath
> >>> control, both are bound to the same web.sitemap XML file. Say I have
> >>> 2 pages, Page 1 and Page 2. Now Page 2 can only be accessed after
> >>> selecting some information on Page 1 (using a CrossPagePostback).
> >>> When the user get's to Page 2, the SiteMapPath control fails to
> >>> render, obviously because Page 2 isn't in the web.sitemap file.
> >>>
> >>> If I put Page 2 in the web.sitemap file, it then get's rendered in
> >>> the Menu control, which I don't want. So, is there any way to "hide"
> >>> certain nodes in a web.sitemap file from the Menu control?
> >>>
> >>> Or is there anyway I can have the SiteMapPath control render
> >>> properly on Page 2 whilst not showing it in the Menu control to the
> >>> user?
> >>>
>
>
>
>

Bookmark and Share