How to Set Access Levels with HttpContext in ASP

When developing ASP applications, you probably want to hide certain elements of your app to not authenticated users such as menus, submenus or even a widget. In this article I will give you a step by step guide on how to establish a certain level of access to your ASP app using HttpContext.

HttpContext, encapsulates all HTTP-specific information about an individual HTTP request.

1. Locate the code that you want to hide. In this example, I have a top bar menu which contains links to sections of my ASP application. I didn’t want to have that menu public, so I made use of the HttpContext in the Site.Master of my ASP application to hide the menu from non authenticated users:

asp menu

2. Now that we have the element that we want to hide, we will wrap around the element with an if statement and check for the identity context:

if (HttpContext.Current.User.Identity.IsAuthenticated)


3. After adding that, save your file and that’s it, the element will be hidden to unauthenticated users.

If you have an ASP app that requires authentication, HttpContext becomes a useful tool to make your site even more secure from anonymous users.

Looking for quality ASP Web Hosting? Look no further than Arvixe Web Hosting!

Happy Hosting!

Rodolfo Hernandez

Tags: , , , , , , , , , , | Posted under ASP .NET 4.0 | RSS 2.0

Author Spotlight

Rodolfo Hernandez

I like photography and reading books. Currently working for Arvixe as Elgg Community Liaison. Elgg Security Expert Web Security Expert CEO of UDP SW Social Web

Leave a Reply

Your email address will not be published. Required fields are marked *