I'm having a heck of a time getting this to work:
DirectoryEntry root = new DirectoryEntry( "IIS://localhost/W3SVC/1/Root" );
DirectoryEntry vdir = root.Children.Add( "MyVirtualPath", "IIsWebVirtualDir" );
On commit changes, the following error occurs:
[UnauthorizedAccessException: Access is denied.]
Default.Page_Load(Object sender, EventArgs e) in \\server\wwwroot$\userfolders\default.aspx.cs:39
The *only* way that I can get this to work is to add NETWORK SERVICE to the administrators group. Seems sort of extreme. Does anyone have any insight on what I need to do to my NETWORK SERVICE to allow it to CommitChanges to a DirectoryEntry object? I've tried tweaking with the Local Policy privileges with little luck. Also, this server is on a domain, so I'm not sure if that plays a role somehow (I tried looking in the Domain Policy and didn't see anything fishy).