Solved

User.Identity.IsAuthenticated

Posted on 2007-11-16
2
218 Views
Last Modified: 2008-02-01
How do I use the User.Identity.IsAuthenticated in the databound area for the menu to only display certain items if the user is logged in?

thanks!
0
Comment
Question by:Starr Duskk
2 Comments
 
LVL 16

Accepted Solution

by:
McExp earned 500 total points
ID: 20302343
Frustratingly I have already answered an almost identical question once before, but I can't find it!

Below is an example of how this can be achieved with the OOB asp:menu control.

Set the following event handler on your asp:menu.

    protected void mMain_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        if (!User.Identity.IsAuthenticated)
        {
            if (e.Item.Parent != null)
            {
                e.Item.Parent.ChildItems.Remove(e.Item);
            }
            else
            {
                e.Item.Enabled = false;
            }
        }
    }

I've striped out lots of code as my live eventHandler is more complicated, so this might not work first time, however, it should be sufficent to demonstrate the concept.

It's important to note that this will not actully stop someone directly navigating to the page that you have hidden. for that you will need to use the full membership solution presented earlier.
0
 
LVL 12

Expert Comment

by:Mortaza Doulaty
ID: 20306969
If you are not using ASP .NET menu, and using other menus like DHTML or JavaScript menus, you can add a function that returns the menu's name, include two menu files (.js) in your project, and for each request of menu, you can process that the user is authenticated or not, so return the appropriate menu's name.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question