Welcome to MSDN Blogs Sign in | Join | Help

How to check if a user belongs to a Security or Distribution group in ASP.Net

If you need to check at Runtime if your User belongs to a Security group. Here's how to do it -  

Assuming the IIS Application has Authentication set to "Windows Authentication". The Request object of HttpContext has the Logged in users Identity which contains Groups. Here is the code which validates if a user belongs to a particular Security group -

var account = new NTAccount(@"Domain\SecurityGroupName"); //The security group you want to check the user belongs to

var groups = HttpContext.Current.Request.LogonUserIdentity.Groups;//Get a collection of Groups the user belongs to

bool hasAccount = groups.Contains(account.Translate(typeof(SecurityIdentifier)));//do the test

Published Wednesday, March 25, 2009 5:54 PM by shahpiyush

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# infoblog » How to check if a user belongs to a Security or Distribution group in ASP.Net

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker