Click here to Skip to main content
15,891,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make controls visible\hidden based on AD group membership.

What I have tried:

I'm fairly new to development. I am building a webforms project in C#, using studio 2015, and .net 4.5. The project uses windows authentication. I have found a way to show\hide controls based on username, which I capture using: System.Web.HttpContext.Current.Request.LogonUserIdentity.Name.Split('\\'). I am looking for a way to check for group membership rather than having to change code to change user permissions on controls.

.....for example, lets say that user "bobr" is in "lab users" AD group, I want to make Panel1 visible.
Posted
Updated 10-Feb-16 4:42am
v2

You're definitely not the first person to want to do this. You could have easily found the answer yourself with a little research effort. Google for "asp.net show controls if user is an administrator[^]".
 
Share this answer
 
Thanks for the response, but I was actually looking for help, not a search term. I found answer myself. For anyone looking to do this same thing, the following in the code-behind worked perfectly:

if (User.IsInRole(@"domainname\groupname"))
{
do something;
}
 
Share this answer
 
Comments
Dave Kreskowiak 11-Feb-16 16:17pm    
What do you think the search term was for? I'd rather teach you how to find the answers yourself than just spoon feed them to you.

You get the answers a lot faster than from a forum and you will probably learn something else along the way.

Without this skill you're going to fail as a software developer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900