Solved

User.Identity.IsAuthenticated

Posted on 2007-11-16
2
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

734 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