Determine The Role of a User in ASP.NET

There are several controls that allow you to display content based on the role a user is in, including:
- LoginView
- LoginStatus
And the web.config file allows us to control which pages can be viewed based on which role a user is in.
But what if you need to determine the role a user is in using the APIs? How do you do that?
It turns out that the API for this is really rather straightforward.
If you are in an ASPX or ASCX file, you can use
if(User.IsInRole("roleNameHere")) { // do something here }
If you are in other code where the User property is not available, you’ll need to use the HttpContext class like we’ve used previously this week to get access to the current context.
if(HttpContext.Current.User.IsInRole("roleName")) { // do something here }
Other post in forms authentication
- WordPress w/ Forms Authentication on IIS6 - May 21st, 2008
- Setting Up Your Forms Based Authentication Database - September 14th, 2009
- Forms Authentication – Creating Users - September 21st, 2009
- Forms Authentication – Managing Users - September 28th, 2009
- Forms Authentication – Manual Authentication - October 5th, 2009
- Determine The Role of a User in ASP.NET - October 13th, 2009
- ASP.NET Assigning a Role to a User - October 19th, 2009
- Authentication - Assigning Permissions to Roles - October 26th, 2009
Other Related Items:
Laptop Lunch Bento Set 2.0 with Purple Outer Container, 5-Inner Containers, Utensils, and User's GuideLaptop Lunch Changing the Way You View Lunch. Whether you're new to bento or are a bento expert, you'll love packing on-the-go meals in this inspirat... Read More >
Aerosoles Women's Crescent Role Mary Jane PumpGet dolled up while staying comfy in the Crescent Role pump from Aerosoles. The mixed leather upper offers fun texture, while the mary-jane strap looks demure. Of course, the brand's iconic comfort features will have you light on your feet all through the day.
Chessex Role Playing Play Mat: Battlemat Double-Sided Reversible Mat for RPGs and Miniature Figure Games (26 in x 23 1/2 in) Squares/HexesChessex
Battlemat with 1 in (25mm) Hex, mats are made from expanded vinyl bring
you the highest quality mat currently available. The Battlemat measures
26in (66cm) x 23 1/2in (60cm)
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!









