1. Home
  2. Computing & Technology
  3. C / C++ / C#
photo of David Bolton
David's C / C++ / C# Blog

By David Bolton, About.com Guide to C / C++ / C#

More on the ASP.NET Development

Tuesday August 26, 2008
As it was a public holiday in the UK on Monday I spent most of it on the website project. I made a break through in that I got my own dynamic menu system working. ASP.NET does provide a menu control but I wanted something that fitted in with my design. Part of the problem was I wanted something fast and didn't want to spend a lot of time playing around with html/css design templates- that can waste a lot of time.

The site started using a pre-designed open source website template called MultiFlex 3. I had all the css/html and it had a nice menu. So I dissected all of the menu elements html, created a menu class and basically put the menu together in a StringBuilder. Also the menu included code to check that the user was logged in and if a logged in user was a Site Admin. The two methods below show how to do this this.

       public bool IsLoggedIn() {
           return (HttpContext.Current.User.Identity.IsAuthenticated) ;
       }

       public bool IsSiteAdmin()
       {
           return (IsLoggedIn() && HttpContext.Current.User.IsInRole ("Site Admin")) ;
       }

This allows access to the all important Admin pages to be restricted by having this in the Page_Load event. below (This is the code that runs when the page has loaded).

    protected void Page_Load(object sender, EventArgs e)
    {
      menus m= new menus() ;
      if (!m.IsSiteAdmin())
      {
          Response.Redirect("sign-in.aspx") ;
      }
    }

If you're not a Site Administrator this redirects you to the sign-in page. Arguably it should redirect unauthenticated users there and authenticated non-Admins elsewhere. I'll add that in...

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.