Wednesday, August 29, 2007

IIS6: Application pool Identity

Referenced post: Separated app pool

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 });

possible values:
0Local System
1Local Service
2Network Service
3Specific 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 });


Anonymous said...


The code that you had posted don't compile (I'm speaking about C# 1.0). Also would be useful to post an entire code sample.

Anyway the post was useful and helped me, thnx sandy

The Last Don said...

You are absolutely right about entire code sample.
Thank you for input!
I usually compile in the C# 2.0
I found some mistakes in the referenced post, and also modified this one.
Hope, it will help.
All the best.