.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Determine if User is in Security Group

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :ASP.Net

 this is what I need to use.

I want to determine if the current user (Windows ID) is in a specific Security Group.  If they are, then certain things will happen on certain forms of the website that I am working on.

I have tried the following code, but I am not getting any results.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim user As WindowsIdentity
        user = WindowsIdentity.GetCurrent()
        Groups(user.Name, True)
End Sub

Public Function Groups(ByVal userDn As String, ByVal recursive As Boolean) As ArrayList
        Dim groupMemberships As New ArrayList()
        Return AttributeValuesMultiString("memberOf", userDn, groupMemberships, recursive)
    End Function

    Public Function AttributeValuesMultiString(ByVal attributeName As String, ByVal objectDn As String, ByVal valuesCollection As ArrayList, ByVal recursive As Boolean) As ArrayList
        Dim ent As New DirectoryEntry(objectDn)
        Dim ValueCollection As PropertyValueCollection = ent.Properties(attributeName)
        Dim en As IEnumerator = ValueCollection.GetEnumerator()

        While en.MoveNext()
            If en.Current IsNot Nothing Then
                If Not valuesCollection.Contains(en.Current.ToString()) Then

View Complete Post

More Related Resource Links

Programatically determine windows security group name SQLServer2005MSSQLUser

When SQL Server 2005 is installed it creates a local group following this convention   SQLServer2005MSSQLUser$<computername>$<instancename>   When the machine is renamed the group name does not change.   Is there a way to programatically (.NET 2.0 or SQL query) determine the group name?May we all make money in the sequel.

How to determine the user that completed a task when the task is assigned to a group?

I am using collect data from a user in a custom workflow.   I am assigning it to a group.   Where is the user stored that actually completes the task?

User group invalid for new document



Defined a user group and a site column of type people/group directing to this group.

Also defined a content type and added the site column to this content type.

When I create a new word document of this content type, word opens displaying my site column ok. But when I enter it, I see that all active directory (AD) entries are displayed. I want it to display only those users I added to the user group I created. Moreover, users can select any user from AD, which makes defining a user group and a site column meaningless.

This problem is only in creating new documents with Word. If I edit properties of an already existing document in my site, everything is ok: I can select only the users in the group.


Can't find AD security group while creating Audience rule


Hi guys,

I'm trying to create audience rule : all members of AD group. But when I try to choose a security group I need I can't find in search window. Though I see another groups. So in a whole the problem is I can't see all the AD groups but only some of them. It doesn't depends on on its type (global or local domain).

What could be a reason?

What is the best way to create user account for big group of people?


I need to create individual account for a big group of people (around 200) from an Excel spreadsheet. What is the best practice? It will take too much time to create account using web form. I think there must be a way to do it. Please advice. I tried to use Stored procedures created by ASP.NET. NOT SURE whether it is a good idea.


Need help with web.config security - Can't figure out where the security group is located in the ap



   We have sepeartate folder called Managers in one of our web apps. And there was a security build around that folder in a web config file as below

<?xml version="1.0"?>
        <allow roles="AllManagers"/>
        <deny users="*"/>

I couldn't figure out where this group located in the application. Usually all our groups are defined in Active directory but except this group. I am not sure if this is defined on the web server or some where in the app itself. Because in the process of figuring out I have changed it to <allow users="*"/> just to make sure if this is the group we are looking for and YES It is and I have access to it. So I need to find out where this is located and add myself as one of the users to this group.

Can any one help me with this mystery.

Thanks in advance,


stsadm Import command + include user security



When I move sites from test to staging to production, I am using the stsadm –o export command with the –includeusersecurity option in the staging environment.  In production environment, I then use the stsadm –o import command with the –includeusersecurity option.  I was assuming that this option was bringing over the security on the exported site only.  This does not seem to be the case.

Last night I exported one sub site to produtction.  Today, I was notified that the security groups on other sub sites have been altered.  


So why is it when using the –includeusersecurity option effect all sub sites and not just the one sub site being moved from staging to production

The Telerik Eastern Canada User Group Tour


Hey!  Telerik is coming to Canada.  Evan Hutnick, Telerik evangelist, will speak at 6 Canadian user groups.


Check Evan's blog for more info

Bookmark and Share

How to determine if current SQL User is admin or owner?

I wish to determine, from my C# application, if the current user has admin or owner rights to the database they are connected to. I beleive I have all the information required: Servername Database name Windows/Database auth username (If database auth) password (if database auth) I'm trying to find a way that using the smo objects (smo.user), but as of yet I cant quite work it out: - How to get the appropriate user - How to determine if that user is an admin/owner. Any tips would be appreciated. If I have posted to the wrong forum, let me know - I couldnt find one that was obviously more appropriate. Thanks.

How to check effective permissions for a user or group for a SQL server object or whole server?

Guys, How do I see effective permissions for a user or group for a SQL server object or whole server? For example, a user is not listed in security/logins, but he is a member of few groups and some of them have assigned permissions on SQL server (again either directly or through membership in other groups) Even when I select an object (a table), check properties/permission – it doesn’t let me select any principal, except those listed on security/logins… Anyway, what is the right way to see effective permissions for a user or group? Sorry for asking such a simple question, I’ve searched but found nothing relevant.

Problem with access to a user in AD group

Hi all, We are managing our security in Sharepoint (WSS 3.0) with AD groups instead of Sharepoint groups. This worked fine until now. For an unknown reason, one single user from an AD group cannot access a page (while other users from the same group can). The group is also a distribution list in AD (so it's a security group and distribution list for emails). It includes several other distribution lists such as: L-All-Corporate-Employees    L-Administration          User 1          User 2           ...     L-Accounting         User 1         ... ...   So far I never had any issue with that kind of approach,  but yesterday we published a new web part page and wanted only the corporate employees to get access to it, so I broke rights inheritance on the page and added the L-All-Corporate-Employees group with View rights. As I already said, I tested with one user from the group (let's say from the L-Administration sub-group) and it works, now I receive an email from another user (let's say from the L-Accounting sub-group) which tells me he doesn't have access... But they're all part of the L-All-Corporate-Employees group, so they should all

Cannot create user: server cannot determine if it is member of a domain

Hi, An instance of our 2008 SP1 SQL Server is running on a computer that was removed from it's domain and then re-added. Now, when I want to create a new login in Management Studio via the nodes Security/Logins, selecting "New Login", entering DOMAIN_NAME\USER_NAME as login name and then click "Search", I get an error message (in German) "Das Programm kann das erforderliche Dialogfeld nicht öffnen, da nicht ermittelt werden kann, ob Computer "COMPUTER_NAME" einer Domäne zugeordnet ist. Schließen Sie dieses Dialogfeld, und wiederholen Sie den Vorgang". Translation: "The program cannot open the required dialog, as it cannot be determined if computer "COMPUTER_NAME" is assigned to a domain. Close this dialog, and repeat the process." But closing the dialog and repeating as suggested does not help. Even restarting the SQL Server service and re-connecting in Management Studio did not help. I keep getting this message. I found, however, that just entering the domain and user name and then clicking Ok seems to add the user. Anyway, it is irritating to get this error message when clicking "Search". How can I tell the engine that the computer is really member of the domain again? Frank

How to get User group in SharePoint Designer 2010 within workflow?

Hi, How to get user group in sharepoint designer within workflow? Basically I have to compair that current user is belongs to particular group or not.  How can I get check user group in workflow's if condition? G. Goyal

check user exists in which group

After entering user name, i want check user belonging to which group, group is some thing like role based if group is something group1 , then i want redirect hime to page 1, if groupis 2  then page 2 like that

current user identity in custom security trimmer

The crux of my problem is that I want to impersonate  a user’s NTLM credentials in the context of a SharePoint custom security trimmer to execute HttpWebRequests to check user access to URLs.  When accessing WindowsIdentity.GetCurent() in the security trimmer, the System.Security.Principal.WindowsIdentity object returns the identity of the application pool running the search query service, NOT the currently logged in user.   When accessing System.Threading.Thread.CurrentPrinciple.Identity in the security trimmer, the Microsoft.IdentityModel.Claims.ClaimsIdentity object of the current logged in user is returned.  However, there is a catch.  …   If I execute the following code in a .NET web application, the cast of the ClaimsIdentity to a WindowsIdentity succeeds because the identity has the authentication type of NTLM.    WindowsIdentity winId = (WindowsIdentity)System.Threading.Thread.CurrentPrincipal.Identity; WindowsImpersonationContext wic = winId.Impersonate(); request.Credentials = CredentialCache.DefaultCredentials; //access means a response comes back when a request is made to the url using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { returnStatus = true; } wic.Undo(); However, when I execute the same code in the context of the SharePoint security trimmer (the search query service li

Redirecting to custom page while clicking on the user/group browse button

Hi, i have created a custom visual web part in visual studio 2010 and i deployed it into sharepoint site by creating a new page in my site. The custom page gets the data of users/groups from database and pass the users to the people picker in sharepoint.Here my question i have a document library where we upload document and get the users page popup that consists of people picker and a user/group browse button.when i click on the (book image button)browse button it will redirect to the user and group search page but here i need to replace my custom  user/group search page with the default one so please help me how to redirect to the custom page by clicking on the user/group browse button,and i need to pass the selected users to the people picker text box........please give me some solution whether this can be done or not if possibe please send me the link or some sample code how to do this   thank you.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend