Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

User.Identity.IsAuthenticated

Posted on 2007-11-16
2
Medium Priority
?
225 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

963 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