Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:38:33+00:00 2026-06-18T12:38:33+00:00

The Problem: When new IIS Application Pools are created and set to use the

  • 0

The Problem: When new IIS Application Pools are created and set to use the Application Pool Identity for permissions, I am unsure how to add those identities to User Groups such as Administrator or Performance Counter Users.

The Background: I’m currently writing a C#.NET library which uses Microsoft.Web.Administration in order to do the following:

  • Detect if IIS 7.x is installed, and if so, what components.
  • Install or upgrade IIS 7.x to a provided list of required components.
  • Create/manage one or more web sites through IIS.
  • Automatically create/manage one application pool per web site

The context is that this library is to be used by executable installers to provide automated deployment of a web server and web sites/services on Windows Server OSes as part of a larger software deployment. So far, all of the above has been implemented, tested, and is (mostly) functional except for the automation of some permissions that need to be performed on Application Pool / Website creation.

In my method for installing a new website, I create a new Application Pool and force it to use the Application Pool Identity:

static public void InstallSite(string name, string path, int port)
{
    Site site;
    var appPoolName = ApplicationPoolBaseName + name;

    using (var iisManager = new ServerManager())
    {
        // Set up a custom application pool for any site we run.
        if (!iisManager.ApplicationPools.Any(pool => pool.Name.Equals(appPoolName)))
        {
            iisManager.ApplicationPools.Add(appPoolName);
            iisManager.ApplicationPools[appPoolName].ManagedRuntimeVersion = "v4.0";
        }
        iisManager.CommitChanges();
    }

    // ... other code here ('site' gets initialized) ...

    using (var iisManager = new ServerManager())
    {
        // Set anonymous auth appropriately
        var config = iisManager.GetWebConfiguration(site.Name);
        var auth = config.GetSection("system.web/authentication");
        auth.SetMetadata("mode", "Windows");
        var authSection = config.GetSection("system.webServer/security/authentication/anonymousAuthentication");
        authSection.SetAttributeValue("enabled", true);
        authSection.SetAttributeValue("userName", string.Empty); // Forces the use of the Pool's Identity.
        authSection = config.GetSection("system.webServer/security/authentication/basicAuthentication");
        authSection.SetAttributeValue("enabled", false);
        authSection = config.GetSection("system.webServer/security/authentication/digestAuthentication");
        authSection.SetAttributeValue("enabled", false);
        authSection = config.GetSection("system.webServer/security/authentication/windowsAuthentication");
        authSection.SetAttributeValue("enabled", false);

        iisManager.CommitChanges();
    }

    // ... other code here ...
}

As I understand it, this would be the best security practice, and I would then add permissions to specific web sites for anything more than minimal system access. Part of this process would be to add these Application Pool identities to User Groups, such as Administrator or Performance Monitor Users. This is where complications arise.

Now, as documented elsewhere, each Application Pool Identity exists in the format of IIS AppPool\\<pool_name> but this faux-user is not listed through the normal GUI user management controls, and does not seem to be accessible through libraries such as System.DirectoryServices.AccountManagement when following this example on SO. Also, other questions about the Application Pool Identity seem to relate to referencing it from within a child website, not from within an installation context.

So, does anyone know what the proper methods are for

  • a) Referencing and accessing Application Pool Identities programmatically.
  • b) Giving Application Pool Identities permissions by adding them User Groups.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:38:34+00:00Added an answer on June 18, 2026 at 12:38 pm

    A solution presented itself sooner than I expected, though it’s not the one I preferred. For anyone interested, there are a couple of additional options on this pinvoke page. The managed solution did not work for me, but the sample using DllImport worked. I ended up adjusting the sample to handle arbitrary groups based on mapping an enum to SID strings, and including another DllImport for:

    [DllImport("advapi32.dll", SetLastError = true)]
    static extern bool ConvertStringSidToSid(
        string StringSid,
        out IntPtr ptrSid);
    

    The modified (working) function looks something like this:

    static public bool AddUserToGroup(string user, UserGroup group)
    {
        var name = new StringBuilder(512);
        var nameSize = (uint)name.Capacity;
        var refDomainName = new StringBuilder(512);
        var refDomainNameSize = (uint)refDomainName.Capacity;
        var sid = new IntPtr();
        switch (group)
        {
            case UserGroup.PerformanceMonitorUsers:
                ConvertStringSidToSid("S-1-5-32-558", out sid);
                break;
            case UserGroup.Administrators:
                ConvertStringSidToSid("S-1-5-32-544", out sid);
                break;
            // Add additional Group/cases here.
        }
    
        // Find the user and populate our local variables.
        SID_NAME_USE sidType;
        if (!LookupAccountSid(null, sid, name, ref nameSize,
            refDomainName, ref refDomainNameSize, out sidType))
            return false;
    
        LOCALGROUP_MEMBERS_INFO_3 info;
        info.Domain = user;
    
        // Add the user to the group.
        var val = NetLocalGroupAddMembers(null, name.ToString(), 3, ref info, 1);
    
        // If the user is in the group, success!
        return val.Equals(SUCCESS) || val.Equals(ERROR_MEMBER_IN_ALIAS);
    }
    

    Hopefully this will be of interest to someone else, and I would still like to know if anyone comes across a working, fully managed solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Windows Server 2008 R2, IIS 7.0. I downloaded umbraco5 sources, created new
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
what's up? I'm facing a problem with IIS 7.5 application, asp.net MVC 3 and
I have web application deployed on my local IIS 7, with application pool configured
I've read where you create a new application pool, one for 2.0 sites and
I am new to Windows IIS and I need to run a php/mysql application
New problem with VS2005 Team Build: Building locally a solution of a mobile client
I have new problem. My code: .method public static void Main() cil managed {
I have a new problem with a python script. When I try to run
I have problem creating new instance of excel 2007 using VBA (from Access 2002).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.