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:
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:
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.