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 });
2 comments:
Hi,
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
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.
Post a Comment