Solved

User.Identity.IsAuthenticated

Posted on 2007-11-16
2
210 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:BobCSD
2 Comments
 
LVL 16

Accepted Solution

by:
McExp earned 500 total points
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now