Solved

User.Identity.IsAuthenticated

Posted on 2007-11-16
2
214 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

20 Experts available now in Live!

Get 1:1 Help Now