In c# we have a function that creates a virtual directory in IIS 6.0
using DirectoryServic es API. The code looks like this:
// log in to IIS
DirectoryEntry rootDir = new
DirectoryEntry( "IIS://localhost/W3SVC/1/Root",ADMIN_USR ,ADMIN_PSWD,Aut henticationType s.Secure);
// create a child virtual directory
DirectoryEntry virtualDir = rootDir.Childre n.Add(name,
rootDir.SchemaC lassName);
// set the virtual directory's physical path
virtualDir.Prop erties["Path"][0] = path;
// the following line throws an UnauthorizedAcc essException if called
from a .aspx page
// but not from a windows desktop application
virtualDir.Comm itChanges();
Logged in as Administrator when I run this code within a windows
application there is no problem. When I run this code called by a
ASP.NET web application I get a "System.Unautho rizedAccessExce ption:
Access is denied." exception.
The web site where the .aspx page that calls this code is set up with
Integrated Windows Authentication or Basic Authentication and a
user/password dialog appears the administrator account is used. In the
web.config for the site these are the settings:
<authenticati on mode="Windows" />
<identity impersonate="tr ue" />
Within the above mentioned code there are entries in a log that show
the process identity of:
WindowsIdentity .GetCurrent().N ame;
Thread.CurrentP rincipal.Identi ty.Name;
and both give the same result: DOMAIN\Administ rator. Is spite of this
we still get the UnauthorizedAcc essException.
What settings have to be changed to get this to work. Any ideas?
Thanks in advance.