Home All Groups Group Topic Archive Search About
Author
8 Jan 2006 6:36 AM
beaudetious
I'm using a Menu web control in an ASP.NET 2.0 web page and I'd populating it
declaratively (sp?) in the web form itself.  One of my menuitem's is only for
admin users to use.  I'd like to learn how to hide this menu item when an
admin user is not logged in.  Or better yet, display it when an admin user is
logged in.  Either way. 

I'm not sure which event to use and how to go about this.  My attempts have
either caused exceptions all over the place.

Thanks,

Brian

Author
8 Jan 2006 2:01 PM
Phillip Williams
Hi Brian,

If you turn the StaticMenuItem collection (that you have declaratively
defined on the web form) into a web.sitemap databound to the Menu control by
a SiteMapDataSource, and define the URL authorization rules in the web.config
then you can have the site map provider filters the site map nodes based on
the user's role setting by turning the SecurityTrimmingEnabled property value
to true.

To see this in a demo look at the QuickStart tutorials:
http://www.asp.net/QuickStart/aspnet/doc/navigation/sitenavapi.aspx#security

Also the Personal Web Site Starter Kit in VS.Net produces a demo site that
uses the same strategy for displaying menus.
Show quoteHide quote
"beaudetious" wrote:

> I'm using a Menu web control in an ASP.NET 2.0 web page and I'd populating it
> declaratively (sp?) in the web form itself.  One of my menuitem's is only for
> admin users to use.  I'd like to learn how to hide this menu item when an
> admin user is not logged in.  Or better yet, display it when an admin user is
> logged in.  Either way. 
>
> I'm not sure which event to use and how to go about this.  My attempts have
> either caused exceptions all over the place.
>
> Thanks,
>
> Brian
Author
8 Jan 2006 2:21 PM
beaudetious
The problem with that approach is that I'm already using the SiteMap for
breadcrumbs with a SiteMapPath control.  I'll have to play around with this
idea to see if I can find a site layout that will work for both my menu and
my breadcrumbs.  Ideally, I'd love to use different sitemaps, but that could
get unweildy in the long run.

Thanks,

Brian

Show quoteHide quote
"Phillip Williams" wrote:

> Hi Brian,
>
> If you turn the StaticMenuItem collection (that you have declaratively
> defined on the web form) into a web.sitemap databound to the Menu control by
> a SiteMapDataSource, and define the URL authorization rules in the web.config
> then you can have the site map provider filters the site map nodes based on
> the user's role setting by turning the SecurityTrimmingEnabled property value
> to true.
>
> To see this in a demo look at the QuickStart tutorials:
> http://www.asp.net/QuickStart/aspnet/doc/navigation/sitenavapi.aspx#security
>
> Also the Personal Web Site Starter Kit in VS.Net produces a demo site that
> uses the same strategy for displaying menus.
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "beaudetious" wrote:
>
> > I'm using a Menu web control in an ASP.NET 2.0 web page and I'd populating it
> > declaratively (sp?) in the web form itself.  One of my menuitem's is only for
> > admin users to use.  I'd like to learn how to hide this menu item when an
> > admin user is not logged in.  Or better yet, display it when an admin user is
> > logged in.  Either way. 
> >
> > I'm not sure which event to use and how to go about this.  My attempts have
> > either caused exceptions all over the place.
> >
> > Thanks,
> >
> > Brian
Author
9 Jan 2006 1:48 AM
sloan
You may want to implement your own custom SiteMapProvider.

Here is a hint to get you started:
public class MySecureMapProvider : XmlSiteMapProvider

{

public MySecureMapProvider ()

{

}



public override bool IsAccessibleToUser(HttpContext context, SiteMapNode
node)

{

//return base.IsAccessibleToUser(context, node);

string currentURL = node.Url;



if (currentURL.Length > 0)

{

return false;//PLACE BUSINESS RULE HERE...

}

return true;





}

}



<siteMap defaultProvider="XmlSiteMapProvider">

<providers>

<add name="XmlSiteMapProvider" type="MySecureMapProvider"
siteMapFile="~/Web.sitemap" securityTrimmingEnabled="true"/>

</providers>

</siteMap>





Show quoteHide quote
"beaudetious" <beaudeti***@discussions.microsoft.com> wrote in message
news:89B6B4B4-55A6-477A-BFFF-1CE345F75EEC@microsoft.com...
> I'm using a Menu web control in an ASP.NET 2.0 web page and I'd populating
it
> declaratively (sp?) in the web form itself.  One of my menuitem's is only
for
> admin users to use.  I'd like to learn how to hide this menu item when an
> admin user is not logged in.  Or better yet, display it when an admin user
is
> logged in.  Either way.
>
> I'm not sure which event to use and how to go about this.  My attempts
have
> either caused exceptions all over the place.
>
> Thanks,
>
> Brian