In referenced post I wrote how to create application pool and assign virtual directory for it..
Now I faced with requirement to change identity from default (Network service) to Local system account) to allow web application more permissions..
Property AppPoolIdentityType should help.
Following code will create pool and set Local System account identity for the pool:
string appPoolName = "myAppPool";
DirectoryEntry poolRoot = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry pool = poolRoot.Children.Add(appPoolName, "IIsApplicationPool");
pool.InvokeSet("AppPoolIdentityType", new Object[] { 0 });
pool.CommitChanges();
possible values:
0 | Local System |
1 | Local Service |
2 | Network Service |
3 | Specific user |
In the case of specific user need to use following additional operations:
pool.InvokeSet("WAMUserName", new Object[] { computerName + @"\" + user });
pool.InvokeSet("WAMUserPass", new Object[] { password });