user240141
user240141

Reputation:

Programatically adding users to IIS_Usrs in C#

I want know how can i add service account users under IIS_USRS user group via some web interface. I need to provide it as some a part of my app.

Environment - IIS 6.0 +

Thanks Amit Ranjan

Upvotes: 0

Views: 238

Answers (1)

mmorel
mmorel

Reputation: 444

You can use ADSI (Active Directory Service Interfaces) by adding a reference to "system.directoryservices.dll" Then you can use a DirectoryEntry like this :

public static void AddUserToGroup(string userDistinguishedname, string groupDistinguishedName) {
    DirectoryEntry group = new DirectoryEntry("LDAP://ldap.mydomain.com/" + groupDistinguishedName);
    DirectoryEntry user = new DirectoryEntry("LDAP://ldap.mydomain.com/" + userDistinguishedname);
    group.Username = "Administrator";
    group.Password = "myAdminPassword";

    using (group) //group is your DirectoryEntry for group
    {
         //member if your user DirectoryEntry
         group.Invoke("Add", new string[] { user.Path });
    } 
}

Hope this help

Upvotes: 2

Related Questions